如何在 C# 中使用 #undef 指令?
#undef 指令允許你取消定義一個符號。以下是語法 −
#undef SYMBOL
例如:
#undef One
當與 #if 指令一起使用時,它會計算為假。讓我們來看一個示例 −
示例
#define One
#undef Two
using System;
namespace Demo {
class Program {
static void Main(string[] args) {
#if (One && TWO)
Console.WriteLine("Both are defined");
#elif (ONE && !TWO)
Console.WriteLine("ONE is defined and TWO is undefined");
#elif (!ONE && TWO)
Console.WriteLine("ONE is defined and TWO is undefined");
#else
Console.WriteLine("Both are undefined");
#endif
}
}
}輸出
Both are undefined
Advertisement
資料結構
網路
RDBMS
作業系統
Java
iOS
HTML
CSS
Android
Python
C 程式設計
C++
C#
MongoDB
MySQL
Javascript
PHP