Simple C# Noop Statement

后端 未结 15 889
面向向阳花
面向向阳花 2021-02-01 01:14

What is a simple Noop statement in C#, that doesn\'t require implementing a method? (Inline/Lambda methods are OK, though.)

My current use case: I want to occupy the c

15条回答
  •  感情败类
    2021-02-01 01:49

    If you want to break into the method you could hardcode a breakpoint:

    System.Diagnostics.Debugger.Break();
    

    Alternatively if you don't compile in release mode, the following line will emit IL which you can break on:

    var a = 1;
    

    You could also write a Debug.Break() that is specific to your machine:

    [Conditional("DEBUG")]
    [Obsolete("Please remove me before checkin.")]
    public static void Break()
    {
        #IF DEBUG
        if (Dns.GetHostName() == "PROTECTORONE")
            Debugger.Break();
        #ENDIF
    }
    

    Note that because of [Conditional("DEBUG")] that method will not get called in call sites during a RELEASE build.

提交回复
热议问题