C# 预处理指令

#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")
        }
    }
}

C# 预处理指令

区域指令

#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
        }
    }
}

C# 预处理指令

 

相关文章:

  • 2022-12-23
  • 2021-06-08
  • 2021-07-31
  • 2021-12-11
  • 2021-11-18
猜你喜欢
  • 2022-12-23
  • 2022-01-01
  • 2021-05-20
  • 2021-10-07
  • 2022-12-23
  • 2022-12-23
相关资源
相似解决方案