Post-Conditions

A post-condition is a contract that is checked after code is executed and is basically used to check the result of some code execution. Continuing with the previous example, you might want to check that the CalculatePerimeter method produces a value greater than zero before returning the result. This kind of post-condition is accomplished via the Contracts.Ensures method, as demonstrated in the following snippet:

image

Also notice how Ensures invokes Contract.Result(Of T). This is basically the representation of the code result, and T is nothing but the expected type, which in this case is Double. This line of code must be placed before ...

Get Visual Basic® 2010 Unleashed now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.