zoukankan      html  css  js  c++  java
  • C# 预处理指令

     #define

    #define Demo
    using System;
    using System.Collections.Generic;
    using System.Linq;
    using System.Text;
    using System.Threading.Tasks;
    
    namespace ConsoleApp1
    {
      
        class Program
        {
            static void Main(string[] args)
            {
    #if Demo
                Console.WriteLine("Run Demo");
    #else
                Console.WriteLine("No run Demo");
    #endif
            }
        }
    }
    Output:
    Run Demo

    #undef

    #define Demo
    #undef Demo
    using System;
    using System.Collections.Generic;
    using System.Linq;
    using System.Text;
    using System.Threading.Tasks;
    
    namespace ConsoleApp1
    {
      
        class Program
        {
            static void Main(string[] args)
            {
    #if Demo
                Console.WriteLine("Run Demo");
    #else
                Console.WriteLine("No run Demo");
    #endif
            }
        }
    }
    Output:
    No run Demo

     条件编译

    使用#define指令定义的标识符 

    True 如果符号已经使用#define定义

    False 其他

    表达式 使用符号和操作符!、==、!=、&&、||构建的

    True 如果为true

    False 其他

    行号指令

    #define Demo
    #undef Demo
    using System;
    using System.Collections.Generic;
    using System.Linq;
    using System.Text;
    using System.Threading.Tasks;
    
    namespace ConsoleApp1
    {
      
        class Program
        {
            static void Main(string[] args)
            {
    #line 233 "huaQ.cs"
                Console.WriteLine("No run Demo")
            }
        }
    }

    区域指令

    #define Demo
    #undef Demo
    using System;
    using System.Collections.Generic;
    using System.Linq;
    using System.Text;
    using System.Threading.Tasks;
    
    namespace ConsoleApp1
    {
      
        class Program
        {
            static void Main(string[] args)
            {
    #region 这个要折叠
                Console.WriteLine("No run Demo");
    #endregion
            }
        }
    }

  • 相关阅读:
    hdu 2680(最短路)
    hdu 1548(最短路)
    hdu 1596(最短路变形)
    hdu 1546(dijkstra)
    hdu 3790(SPFA)
    hdu 2544(SPFA)
    CodeForces 597B Restaurant
    CodeForces 597A Divisibility
    CodeForces 598E Chocolate Bar
    CodeForces 598D Igor In the Museum
  • 原文地址:https://www.cnblogs.com/yinghualuowu/p/9371531.html
Copyright © 2011-2022 走看看