May 2010
Intermediate to advanced
1272 pages
61h 18m
English
You add preconditions contracts to tell the compiler that the code can be executed only if it respects the specified contract. Generally preconditions are useful replacements for custom parameters validation rules. For example, consider the following simple method that multiplies two numbers:

Inside the method body, the code checks for valid parameters; otherwise, it throws an exception. This is common, but code contracts provide a good way, too. The preceding method could be rewritten with code contracts as follows:

So you just invoke ...
Read now
Unlock full access