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