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

前端 未结 5 916
梦谈多话
梦谈多话 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:10

    In Debug mode:

    #if DEBUG
                System.Console.WriteLine("Debug version");
    #endif
                System.Console.WriteLine("Output");
    

    Output as

    Debug version
    Output
    

    In Release mode:

    #if DEBUG
                System.Console.WriteLine("Debug version");
    #endif
                System.Console.WriteLine("Output");
    

    Output as

       Output
    

    read this: #if (C# Reference)

    Usage: If you have a set of values to be tested in the debug mode and not in the release mode you can use #if DEBUG

提交回复
热议问题