8

I've looked up the difference on the microsoft site but can't really see the difference. links to the website are below

Any additional explaination would be great

Using visual studio c#

Mark Seemann
  • 225,310
  • 48
  • 427
  • 736

1 Answers1

9

Requires is a precondition, meaning that the condition specified must be true prior to the method being invoked. Ensures is a postcondition, meaning that the method guarantees that the condition specified will be true after the method call is complete.

Preconditions and/or postconditions may be violated while the method is executing: the tests are done upon entry to and exit from of the method, respectively. An invariate condition is a contract that says that the specified condition always holds true.

Read Bertrand Meyer's Object-Oriented Software Construction for more [much more] detail. This paper by Meyer is shorter [much shorter].

Nicholas Carey
  • 71,308
  • 16
  • 93
  • 135
  • nice one. I would also suggest `Provable Code` or `Code Contracts` courses at pluralsight.com. They give a very nice drill down into design by contract using Microsoft Code Contracts – Ilya Ivanov Oct 29 '13 at 01:28