Code Contracts in C#
Code contracts introduced in .NET Framework 4.0 is a useful but underutilized feature. It enables a developer to publish various conditions that are necessary within an application. There is a concept called Design by contract where you can define pre-conditions, post-conditions, and invariants on class methods. The basic idea was for a method to define a contract which states conditions that must be true when the method gets called . This is also called as preconditions. The method must also define conditions that must be true when it finishes execution . This is called as postconditions. The method can also define conditions that should remain true while the program is running . This is called as invariants. .NET 4.5 introduces a new feature in Code Contracts called as abbreviations. Abbreviations are useful in scenarios where some contracts are required repeatedly. So if a method contains multiple contracts, just decorate that meth...