Visual Studio
코드 계약
수색…
비고
코드 계약을 완전히 활용하려면 Visual Studio 용 확장 프로그램 을 설치해야합니다. 또한 코드 계약 사용자 설명서가 있습니다.
표준 전제 조건
using System.Diagnostics.Contracts;
public int DivideNumbers(int numerator, int denominator)
{
Contract.Requires(denominator != 0);
return numerator / denominator;
}
특정 예외를 throw하는 사전 조건
using System.Diagnostics.Contracts;
public int DivideNumbers(int numerator, int denominator)
{
Contract.Requires<ArgumentOutOfRangeException>(denominator != 0);
return numerator / denominator;
}
전후 조건
using System.Diagnostics.Contracts;
public int IncrementByRandomAmount(int input)
{
Contract.Requires<ArgumentNullException>(input != null); // Don't allow null parameter.
Contract.Requires<ArgumentOutOfRangeException>(input < int.MaxValue); // We can't do anything if we're given int.MaxValue.
Contract.Ensures(Contract.Result<int>() > input); // Return value will be greater than input value.
Random rnd = new Random();
input += rnd.Next(1, 13); // Creates a number between 1 and 12 and adds it to input.
return input;
}
Modified text is an extract of the original Stack Overflow Documentation
아래 라이선스 CC BY-SA 3.0
와 제휴하지 않음 Stack Overflow