In C++ we can use #ifdef to eliminate some debug statements when we release. C# is different from C++ in preprocessor. Can I still get the same result useing C# #if. We want to eliminate ALL debug statements by change one place and we have several different types of debug statements. Can have one file which contains ALL our #ifdef flags to turn on or turn off those debug statements? thanks
相关问题
- Sorting 3 numbers without branching [closed]
- Graphics.DrawImage() - Throws out of memory except
- Why am I getting UnauthorizedAccessException on th
- 求获取指定qq 资料的方法
- How to know full paths to DLL's from .csproj f
Use something like:
You can wrap code in:
However, I don't recommend this. It's often a better alternative to just make a method and flag it with the
[Conditional("DEBUG")]
attribute. See Conditional on MSDN for more details. This allows you to make debug only methods:Then, you can call this normally:
The according the MSDN docs
So you can't have a file that defines several other defines that are used throughout your program. The easiest way to do this would be to have different configurations on your project file and specifying the list of defines for each configuration on the command line to the compiler.
Update: You can set your project defines in Visual Studio by right-clicking on your project and selecting Properties. Then select the Build tab. Under general you can specify the defines to be sent to the compiler under "Conditional compilation symbols". You can define different project settings using the Configuration Manager (Build->Configuration Manager)
Update 2: When the "Conditional compilation symbols" are specified, Visual Studio emits a
/define
on the command line for the compiler (csc.exe for C#), you can see this by examining the output window when building your project. From the MSDN docs for csc.exe