C#预处理命令

版权声明:本文为博主原创文章,未经博主允许不得转载。 https://blog.csdn.net/bad_boy627056049/article/details/73611763

1.#define 和#undefine

#define用法

#define DEBUG//告诉编译器存在给定名称的符号,但是它不是变量,不是代码的一部分,只在编译时存在
#undefined DEBUG//删除定义的该符号,如果符号不存在,则该表达式没有意义

  • #define本身没有用,必须和其他的预处理命令配合使用,如#if
  • #define与#undefine必须放在C#源文件的开头位置

2.#define 和#undefine

#if,#elif,#else,#endif的用法

int DoSomeWork(double x)
{
    #if DEBUG
        Consol.WriteLine(x);
    #endif
}

条件编译:
强调内容#elif=else if

3.#warning 和#error

#warning 编译,但是提醒
#error 编译停在此处,提醒

4.#region 和#endregion

标记一个代码块

猜你喜欢

转载自blog.csdn.net/bad_boy627056049/article/details/73611763