c# - Debug.WriteLine() 参数表达式求值副作用是否发生在发布版本中?

标签 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()(和类似函数)的参数表达式求值副作用是否发生在发布版本中?我不确定“调试元素”的真正含义。

最佳答案

这很简单,你自己试试看:

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

在 Debug模式下,控制台打印 1。在 Release模式下,控制台打印 0。

关于c# - Debug.WriteLine() 参数表达式求值副作用是否发生在发布版本中?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/38017881/

相关文章:

c# - 是否存在使用 C# 动态调度的 VB "Variant"实现之类的东西?

c# - Visual Studio : Suppress warnings for all files in a namespace

visual-studio - 发布配置文件复制文件到相关目的地

c# - 指定数量集的任意加法组合,达到特定目标值

c# - 在 .NET 中,为什么常量在编译时而不是在 JIT 时求值?

c# - 是否有使用属性将注入(inject)参数绑定(bind)到成员字段的包?

c# - 在服务器应用程序中使用 threadPool 或 new thread() 进行多线程

.net - 单元测试无法访问另一个项目中的设置

c# - c# .net 中的 tabindex 问题

c# - 检索进程网络使用情况