不要在发布版本中出现Debug.WriteLine()参数表达式计算的副作用
本文关键字:参数 WriteLine Debug 表达式 副作用 计算 布版本 版本 | 更新日期: 2023-09-27 17:49:15
根据对这个问题的公认答案:
When the application is compiled in the release configuration,
the Debug elements will not be compiled into the code.
Debug.WriteLine()(和类似的)的参数表达式评估副作用在发布版本中发生吗?我不确定"调试元素"到底是什么意思
这很容易自己尝试:
class Program
{
static void Main(string[] args) {
int i = 0;
Debug.WriteLine(i++);
Console.WriteLine(i);
Console.ReadLine();
}
}
在调试模式下,控制台打印1。在释放模式下,控制台打印0。