Created
November 18, 2012 11:08
.NET Code Contracts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public static int Divide(int number, int divisor) | |
{ | |
if (divisor == 0) throw new Exception(); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public static int Divide(int number, int divisor) | |
{ | |
Contract.Requires(divisor != 0); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public static double Divide(int number, int divisor) | |
{ | |
Contract.Requires(divisor > 0); | |
return number / divisor; | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Divide(1, 2); | |
Divide(1, 0); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public static void TestCodeContract(int value) | |
{ | |
TestLimits(105); | |
TestLimits(95); | |
TestLimits(115); | |
} | |
public static void TestLimits(int i) | |
{ | |
Contract.Requires(i > 100); | |
Contract.Requires(i < 110); | |
//Do Something | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public static void TestCodeContract(int value) | |
{ | |
TestLimits(value); | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public static void TestCodeContract(int value) | |
{ | |
if(value > 100 && value < 110) | |
TestLimits(value); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment