In order to fully understand and take advantage of the new features and enhancements provided with the coming of the new .NET Framework 4.0, I would like to get an example of
Have you ever seen a NullReferenceException
and wished that the compiler could have warned you about it at compile time to avoid finding out the hard way - with your program crashing?
With code contracts you can write things like:
Contract.Requires(foo != null);
This isn't just a runtime check - you can set it up so that if you call this function with an argument that might be null you will get a compile error.
Here's a real world example:
Address GetAddress(Customer customer)
{
Contract.Requires(customer != null, "customer");
return addressBook.FindCustomer(customer);
}