When should I use Debug.Assert()?

后端 未结 20 1711
说谎
说谎 2020-11-30 16:12

I\'ve been a professional software engineer for about a year now, having graduated with a CS degree. I\'ve known about assertions for a while in C++ and C, but had no idea t

20条回答
  •  感动是毒
    2020-11-30 17:11

    According to the IDesign Standard, you should

    Assert every assumption. On average, every fifth line is an assertion.

    using System.Diagnostics;
    
    object GetObject()
    {...}
    
    object someObject = GetObject();
    Debug.Assert(someObject != null);
    

    As a disclaimer I should mention I have not found it practical to implement this IRL. But this is their standard.

提交回复
热议问题