คำสั่ง #undef ช่วยให้คุณสามารถกำหนดสัญลักษณ์ได้ ต่อไปนี้เป็นวากยสัมพันธ์ −
#undef SYMBOL
ตัวอย่างเช่น
#undef One
โดยจะประเมินเป็นเท็จเมื่อใช้ร่วมกับ #if directive เรามาดูตัวอย่างกัน −
ตัวอย่าง
#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