zoukankan      html  css  js  c++  java
  • 预处理指令关键字

    #if、#else、#elif、#endif
    这组指令主要用于在调试环境下代码进行条件编译时,用于控制编译器对某个代码段是否进行编译。
    #define release
    using System;
    using System.Collections.Generic;
    using System.Linq;
    using System.Text;
    using System.Linq.Expressions;
    using System.Dynamic;
    using System.ComponentModel;
    
    namespace ConsoleApplication
    {
    
        class Program
        {
            static void Main(string[] args)
            {
                #if debug
                Console.WriteLine("It's debug.");
                #elif release
                Console.WriteLine("It's release.");
                #endif
                Console.ReadLine();
            }
        }
    }
    View Code

    用CondintionalAttribute特性来代替#if/#endif程序块。

    #define debug
    using System;
    using System.Collections.Generic;
    using System.Linq;
    using System.Text;
    using System.Linq.Expressions;
    using System.Dynamic;
    using System.ComponentModel;
    using System.Diagnostics;
    
    namespace ConsoleApplication
    {
    
        class Program
        {
            static void Main(string[] args)
            {
                ShowDebug();
                Console.ReadLine();
            }
            [Conditional("debug"), Conditional("release")]
            static void ShowDebug()
            {
                Console.WriteLine("It's debug or release.");
            }
        }
    }
    View Code
    #define、#undef
    这两个指令分别用于定义和取消定义一个给定名词的符号,该符号可以应用#if指令作为判断条件,和其他指令搭配才有意义。
     
    #warning、#error
    #warning指令用于发出警告信息,#error指令用于发出错误信息。
    #define TRACE_WARNING
    #define TRACE_ERROR
    using System;
    using System.Collections.Generic;
    using System.Linq;
    using System.Text;
    using System.Linq.Expressions;
    using System.Dynamic;
    using System.ComponentModel;
    using System.Diagnostics;
    
    namespace ConsoleApplication
    {
    
        class Program
        {
            static void Main(string[] args)
            {
                #if TRACE_WARNING
                    #warning "别忘了还有事情没有处理。"
                #endif
    
                #if TRACE_ERROR
                    #error "这里是错的,注意哦"
                #endif
                Console.WriteLine("asfsdfsdfsadf");
                Console.ReadLine();
            }
    
        }
    }
    View Code
  • 相关阅读:
    (1)spark核心RDD的概念解析、创建、以及相关操作
    docker常用命令
    asyncpg:异步操作PostgreSQL
    python调用golang编写的动态链接库
    使用C语言为python编写动态模块(3)--在C中实现python中的类
    使用C语言为python编写动态模块(2)--解析python中的对象如何在C语言中传递并返回
    flask的orm操作
    python下载指定的版本包
    flask 的管理模块的功能add_template_global、send_from_directory
    docker 的简单使用
  • 原文地址:https://www.cnblogs.com/scmail81/p/8605568.html
Copyright © 2011-2022 走看看