哪些命名约束适用于 C# 条件编译符号?
What naming constraints apply to C# conditional compilation symbols?
C# 中的条件编译符号的名称适用什么规则?
我咨询过 #define documentation, the /define compiler switch documentation, and the C# language specification。 #define 和 /define 文档只是说您可以定义符号名称,并且符号名称不会与变量名称冲突。语言规范说有一个 "conditional-symbol" 标记,但似乎没有评论什么构成有效的符号标记 - 我可能没有找到正确的地方?
- 条件编译符号可以以数字开头吗?
- 它们是否可以包含特殊字符,例如 . (例如,用于与版本号相关的符号)?不间断空格怎么样?
- 像#、{}、[]这样的字符呢?
编辑:link到权威文档会很有用
符号定义可在规范的第 2.5.1 节中找到:
2.5.1 Conditional compilation symbols
The conditional compilation functionality provided by the #if
, #elif
, #else
, and #endif
directives is controlled through pre-processing expressions (§2.5.2) and conditional compilation symbols.
conditional-symbol:
Any identifier-or-keyword except true
or false
这在 same section and in the grammar under §C.1.10, but note that the spec that's available online is for a very old version of the language and should not be used as a reference. You can find the latest available spec in C:\Program Files (x86)\Microsoft Visual Studio 14.0\VC#\Specifications33 or for download 中在线反映(显然,在撰写本文时它仍然是 C# 5.0)。
标识符或关键字的定义可以在§B.1.6标识符中找到。
C# 中的条件编译符号的名称适用什么规则?
我咨询过 #define documentation, the /define compiler switch documentation, and the C# language specification。 #define 和 /define 文档只是说您可以定义符号名称,并且符号名称不会与变量名称冲突。语言规范说有一个 "conditional-symbol" 标记,但似乎没有评论什么构成有效的符号标记 - 我可能没有找到正确的地方?
- 条件编译符号可以以数字开头吗?
- 它们是否可以包含特殊字符,例如 . (例如,用于与版本号相关的符号)?不间断空格怎么样?
- 像#、{}、[]这样的字符呢?
编辑:link到权威文档会很有用
符号定义可在规范的第 2.5.1 节中找到:
2.5.1 Conditional compilation symbols
The conditional compilation functionality provided by the
#if
,#elif
,#else
, and#endif
directives is controlled through pre-processing expressions (§2.5.2) and conditional compilation symbols.conditional-symbol:
Any identifier-or-keyword excepttrue
orfalse
这在 same section and in the grammar under §C.1.10, but note that the spec that's available online is for a very old version of the language and should not be used as a reference. You can find the latest available spec in C:\Program Files (x86)\Microsoft Visual Studio 14.0\VC#\Specifications33 or for download 中在线反映(显然,在撰写本文时它仍然是 C# 5.0)。
标识符或关键字的定义可以在§B.1.6标识符中找到。