.net 4.0 Code Contracts. When to use? When are they a waste of time?

后端 未结 3 1280
感情败类
感情败类 2020-12-31 17:17

I have been studying .NET 4.0 Code Contracts and looking on stackoverflow as well at question regarding this.

I still have never come across any sample code that use

3条回答
  •  悲哀的现实
    2020-12-31 17:33

    there is field of study on contracts: http://en.wikipedia.org/wiki/Design_by_contract it was long before they were introduced in .net.

    Code contracts are useful to give answers to following questions:

    • What does method expect?
    • What does method guarantee?
    • What does method maintain?

    If you can write small and readable contract for those questions then use it.

提交回复
热议问题