What is the usage of #if DEBUG pre-processor directive in C#? When must we use this?

前端 未结 5 913
梦谈多话
梦谈多话 2021-01-11 10:55

What is the usage of #if DEBUG pre-processor directive in C#? When must we use this?

5条回答
  •  孤城傲影
    2021-01-11 11:09

    You might feel more comfortable with the Conditional attribute, which can be used to exclude entire methods, without needing to complicate the source with conditionals on the calling side:

    [Conditional("DEBUG")]
    void Foo()
    {
    }
    

    Foo() can be safely called in both debug and release - however in release mode, it would be a no-op.

提交回复
热议问题