#define คำสั่งตัวประมวลผลล่วงหน้ากำหนดลำดับของอักขระ เรียกว่าสัญลักษณ์ มันสร้างค่าคงที่เชิงสัญลักษณ์
#define ให้คุณกำหนดสัญลักษณ์โดยการใช้สัญลักษณ์เป็นนิพจน์ที่ส่งผ่านไปยังคำสั่ง #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
}
}
}