C#预处理控制行

特性#error和#warning使得代码可以把警告和错误的条件报告给编译程序,来查出标准的编译时的警告和错误。

pp-con trol-line:  


#error pp-message  


#warning pp-message  


pp-message:  


pp-tokensopt 

举个例子帮助大家理解

#warning Code review needed before check-in  


#define DEBUG  


#if DEBUG && RETAIL  


#error A build can't be both debug and retail!  


#endif  


class Class1  


{…} 

这将总是产生警告(“Code review needed before check-in"),并且如果予处理修饰符DEBUG 和RETAIL 都被定义,还会产生错误。

C#预处理标识符

C#预处理标识符使用和规则C#标识符文法相似的文法:

pp -identifi er:  


pp-ava ilable-identifier  


pp-ava ilable-identifi er:  


A pp-identif ier-or-keyword that is not true or false  


pp-id entif ier-or-keyword:  


identifi er-start-character identif ier-part-characters opt 

true 和false 符号不是合法的预定义指示符,所以不能用于#define 的定义和#undef 的反定义。

C#预处理表达式