C# #if #else #endif 的使用
来源:互联网 发布:加盟淘宝母婴店 编辑:程序博客网 时间:2024/06/05 23:11
如果 C# 编译器遇到最后面跟有 #endif 指令的 #if 指令,则仅当指定的符号已定义时,它才会编译这两个指令之间的代码。不能对符号赋予数值;C# 中的 #if 语句是 Boolean,结合使用 #if 与 #else、#elif、#endif、#define 和 #undef 指令,可以根据一个或多个符号是否存在来包含或排除代码。 在编译调试版本的代码或针对特定配置进行编译时,这会很有用。以 #if 指令开始的条件指令必须用 #endif 指令显式终止。
超简单的例子:
static void Main(string[] args)
{
A();
}
public static void A()
{
#if true
Console.WriteLine("我是A");
#else
Console.WriteLine("我是B");
#endif
Console.Read();
}
}
运行结果:输出:我是A;
class Program
{
static void Main(string[] args)
{
A();
}
public static void A()
{
#if false
Console.WriteLine("我是A");
#else
Console.WriteLine("我是B");
#endif
Console.Read();
}
}
运行结果:输出:我是B;
- C# #if #else #endif 的使用
- C#的#if false #else #endif
- 关于#define 、#if、#endif、#else的使用
- #if、#elif、#else、#endif的使用
- #if, #elif, #else, #endif 使用
- #if, #elif, #else, #endif 使用
- #if, #elif, #else, #endif 使用
- #if, #elif, #else, #endif 使用
- #if, #elif, #else, #endif 使用
- #if, #elif, #else, #endif 使用
- #if, #elif, #else, #endif 使用
- #if, #elif, #else, #endif 使用
- #if, #elif, #else, #endif 使用
- #if, #elif, #else, #endif 使用
- #if, #elif, #else, #endif 使用
- #if, #elif, #else, #endif 使用
- #if, #elif, #else, #endif 使用
- #if, #elif, #else, #endif 使用
- java中利用泛型反射创建数据库
- 用于构建交互式图表的最佳 jQuery 图表库
- git am PATCH 失败的处理方法
- 常用php函数,来自互联网
- C#单例模式
- C# #if #else #endif 的使用
- 安装Haraka时遇到的错误gyp ERR! stack Error: spawn ENOENT的解决方案
- xFace App Workspace 介绍
- 字符颜色值转UIColor
- 逻辑接口及在PMIP中的应用 阅读摘要
- Ubuntu12.04如何修改窗口背景色为眼睛保护色来保护眼睛,强力推荐!!
- 序列比较
- LoadRunner产生随机数
- cookie 和session 的区别详解