如何在 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

更新於: 2020 年 6 月 20 日

223 次瀏覽

啟動你的 職業生涯

完成課程來獲得認證

開始
Advertisement
© . All rights reserved.