C#预处理命令
- #define和#undef
#define 它告诉编译器存在给定名称的符号
#undef 它删除符号的定义 - #if #elif #else #endif
这些指令告诉编译器是否编译某个代码块
#define DEBUG
#define BUG
static void Main(string[] args)
{
#if BUG
Console.WriteLine("出BUG了");
#elif DEBUG
Console.WriteLine("BUG解决了");
#else
Console.WriteLine("666666");
#endif
Console.ReadKey();
}
#if =if
#elif =else if
#else =else
#endif 结束if
- #warning和#error
#warning产生警告
#error产生错误 - #regin和#endregin
#region 主函数
static void Main(string[] args)
{
Console.WriteLine("666666");
Console.ReadKey();
}
#endregion
会变为
主函数
这在大量的代码中会优化可读性