Debug.WriteLine()参数表达式评估副作用是否在发布版本中发生?

时间:2016-06-24 16:17:11

标签: c# .net visual-studio

根据this问题的接受答案:

When the application is compiled in the release configuration, 
the Debug elements will not be compiled into the code.

Debug.WriteLine()(和类似的)的参数表达式评估副作用是否在发布版本中发生?我不确定“调试元素”究竟意味着什么。

1 个答案:

答案 0 :(得分:5)

这很容易尝试自己:

class Program
{
    static void Main(string[] args) {
        int i = 0;
        Debug.WriteLine(i++);
        Console.WriteLine(i);
        Console.ReadLine();
    }
}

在调试模式下,控制台打印1.在释放模式下,控制台打印0。