C#中有没有办法从C/C++复制'#ifndef _DEBUG'?

Sam*_*mbo 30 c# debugging programming-languages

我想根据我是否在调试模式下构建来有条件地排除/包含代码.

我可以像在C++中一样使用像#ifndef _DEBUG这样简单的东西吗?

Dav*_*kle 51

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

#if !DEBUG
    Console.WriteLine("NOT Debug version");
#endif
Run Code Online (Sandbox Code Playgroud)

看到这个.

  • ...并且在滚动自己之前分别考虑使用Trace/Debug输出.断言也是如此. (4认同)