zoukankan      html  css  js  c++  java
  • ConditionalAttribute 类

    指示编译器应忽略方法调用或属性,除非已定义指定的条件编译符号。

    #define CONDITION1
    #define CONDITION2
    using System;
    using System.Diagnostics;

    class Test
    {
        static void Main()
        {              
            Console.WriteLine("Calling Method1");
            Method1(3);
            Console.WriteLine("Calling Method2");
            Method2();

            Console.WriteLine("Using the Debug class");
            Debug.Listeners.Add(new ConsoleTraceListener());
            Debug.WriteLine("DEBUG is defined");
        }

        [Conditional("CONDITION1")]
        public static void Method1(int x)
        {
            Console.WriteLine("CONDITION1 is defined");
        }

        [Conditional("CONDITION1"), Conditional("CONDITION2")] 
        public static void Method2()
        {
            Console.WriteLine("CONDITION1 or CONDITION2 is defined");
        }
    }

    /* When compiled as shown, the application (named ConsoleApp) produces the following output. Calling Method1 CONDITION1 is defined Calling Method2 CONDITION1 or CONDITION2 is defined Using the Debug class DEBUG is defined */

  • 相关阅读:
    指针类型
    集合类型
    VMware打开虚拟机没反应的解决方案(全面汇总)
    redis主从|哨兵|集群模式
    MYSQL一次千万级连表查询优化
    StackExchange.Redis通用封装类分享
    Redis-五种数据类型解析
    Redis并发问题
    C#委托和事件
    Invoke 和 BeginInvoke 的区别
  • 原文地址:https://www.cnblogs.com/qook/p/5504209.html
Copyright © 2011-2022 走看看