系统已经默认定义了DEBUG
#if DEBUG只在调试代码时生效,release版本不包含这部分内容
- #if DEBUG
- Console.WriteLine("测试标准OPC UA");
- #endif
-
- #if DEBUG
- Console.WriteLine("Debug...");
- #else
- // 当把开发模式改成Release时,执行此处
- Console.WriteLine("Release...");
- #endif
自定义宏,#define只能在最上面添加
- #define TEST // 定义宏标识符,但不能定义宏数值常量和宏函数
-
- using System;
- namespace Demo
- {
- class Program
- {
- static void Main(string[] args)
- {
- #if TEST
- Console.WriteLine("Debug...");
- #else
- // 没有在第一行定义TEST时,执行此处
- Console.WriteLine("Release...");
- #endif
-
- #warning This is a warning.// 生成警告
- }
- }
- }
&&与、||或:有一个符号定义了就可以正常包含里面的内容
- #define TEST
-
- using System;
-
-
- #if TEST && DEBUG
- Console.WriteLine("与");
- #endif
-
- #if TEST || DEBUG
- Console.WriteLine("或");
- #endif
-
- Console.WriteLine("run");