gpt4 book ai didi

c# - 哪些命名约束适用于 C# 条件编译符号?

转载 作者:行者123 更新时间:2023-11-30 16:02:56 24 4
gpt4 key购买 nike

什么规则适用于 C# 中的条件编译符号的名称?

我咨询过#define documentation , /define compiler switch documentation , 和 C# language specification . #define 和/define 文档只是说您可以定义符号名称,并且符号名称不会与变量名称冲突。语言规范说有一个“条件符号” token ,但似乎没有评论什么构成有效的符号 token - 我可能没有找到正确的地方?

  • 条件编译符号可以以数字开头吗?
  • 它们能否包含特殊字符,例如 . (例如,用于与版本号相关的符号)?不间断空格怎么样?
  • #、{}、[] 之类的字符怎么样?

编辑:指向权威文档的链接会很有用

最佳答案

符号定义可以在规范的 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

这在线反射(reflect)在 same section 中在grammar在 §C.1.10 下,但请注意,在线提供的规范适用于该语言的非常旧版本,不应用作引用。您可以在 C:\Program Files (x86)\Microsoft Visual Studio 14.0\VC#\Specifications\1033 或 download 中找到最新的可用规范。 (显然,在撰写本文时,它仍然是 C# 5.0)。

identifier-or-keyword 的定义可以在§B.1.6 Identifiers 中找到。

关于c# - 哪些命名约束适用于 C# 条件编译符号?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/37107832/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com