gpt4 book ai didi

.Net/CLR 标识符

转载 作者:行者123 更新时间:2023-12-04 06:19:42 29 4
gpt4 key购买 nike

我想知道,.Net 标识符中接受哪些字符?

不是 C# 或 VB.Net,而是 CLR。​​

我问这个的原因是我正在查看 yield return 语句是如何实现的 (C# In Depth),并看到它编译成如下代码:

public int <count>5__1;

还有其他我可以使用的标识符字符吗?此代码不会公开。

最佳答案

这受 CLS 规范第 8.5.1 章“有效名称”的约束:

CLS Rule 4: Assemblies shall follow Annex 7 of Technical Report 15 of the Unicode Standard 3.0 governing the set of characters permitted to start and be included in identifiers, available on-line at http://www.unicode.org/unicode/reports/tr15/tr15-18.html. Identifiers shall be in the canonical format defined by Unicode Normalization Form C. For CLS purposes, two identifiers are the same if their lowercase mappings (as specified by the Unicode locale-insensitive, one-to-one lowercase mappings) are the same. That is, for two identifiers to be considered different under the CLS they shall differ in more than simply their case. However, in order to override an inherited definition the CLI requires the precise encoding of the original declaration be used.

或者换句话说,它没有指定verboten 字符列表,它只关心能够比较字符串而不会出现意外。这是 CLR 必须做的所有事情。编译器的工作要困难得多,它必须能够识别程序中的标记,这是词法分析器的工作。实用的词法分析器实现对标识符中的有效字符设置规则。例如,不要以数字开头标识符。

关于.Net/CLR 标识符,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/6744114/

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