#define预处理程序指令定义了一系列字符,称为符号。它创建符号常量。
#define允许您定义一个符号,从而通过将该符号用作传递给#if指令的表达式,该表达式的计算结果为true。
这是一个例子-
#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 } } }