How can I use debugbreak() in C#?

后端 未结 5 1177
臣服心动
臣服心动 2020-12-03 00:53

What is the syntax and which namespace/class needs to be imported? Give me sample code if possible. It would be of great help.

5条回答
  •  醉梦人生
    2020-12-03 01:32

    I also like to check to see if the debugger is attached - if you call Debugger.Break when there is no debugger, it will prompt the user if they want to attach one. Depending on the behavior you want, you may want to call Debugger.Break() only if (or if not) one is already attached

    using System.Diagnostics;
    
    //.... in the method:
    
    if( Debugger.IsAttached) //or if(!Debugger.IsAttached)
    {
      Debugger.Break();
    }
    

提交回复
热议问题