C# 中的 if/then 指令在调试和发布之间有什么区别?
在 Visual Studio 中,调试模式和发布模式是用于构建 .Net 项目的不同配置。
选择调试模式逐个调试 .Net 项目,选择发布模式最终构建程序集文件(.dll 或 .exe)。
要更改构建配置 −
从构建菜单中,选择配置管理器,然后选择调试或发布。或在工具栏中,从解决方案配置列表中选择调试或发布。
写在 #if debug 中的代码只有在代码在调试模式内运行时才会执行。
如果代码在发布模式内运行,则 #if Debug 将为 false,并且不会执行其中的代码。
示例
class Program{
static void Main(string[] args){
#if DEBUG
Console.WriteLine("Mode=Debug");
#else
Console.WriteLine("Mode=Release");
#endif
Console.ReadLine();
}
}输出
if in Debug Mode Mode=Debug if in Release Mode Mode=Release
广告
数据结构
网络
RDBMS
操作系统
Java
iOS
HTML
CSS
Android
Python
C 编程
C++
C#
MongoDB
MySQL
Javascript
PHP