木子屋 Dnawo's BLOG

C#预处理指令

👤 dnawo 📅 2009-01-19 👁 3532 👍 0 💬 0 🔄 本站原创
C#预处理指令主要有以下几种:

·条件编译指令:#if、#elif、#else 和 #endif,用于按条件跳过源代码中的节
·声明指令:#define 和 #undef,分别用于定义和取消定义条件编译符号
·诊断指令:#error 和 #warning,分别用于发出错误和警告
·区域指令:#region 和 #endregion,用于显式标记源代码中的节
·行指令:#line,用于控制行号

说明:声明指令必须位于源文件中所有实代码的前面,否则将发生编译时错误。

示例:

#define AAA
#undef BBB

#region 判断条件编译符号是否定义

#if AAA
#warning AAA is defined
#else
#error AAA is not defined
#endif

#if !BBB
#error BBB is not defined
#else
#warning BBB is defined
#endif

#endregion

图片

评论(0)

暂无评论。

计算题
评论需审核通过后显示
← 上一篇 .NET事务处理使用示例 下一篇 → ASP.NET缓存依赖之SQL Server篇