为什么这个名字用下划线不符合CLS?下划线、不符合、这个名字、CLS

2023-09-02 21:30:05 作者:候你已久 何时归来

为什么我得到的编译器警告

  

标识符Logic.DomainObjectBase._isNew'是不符合CLS

以下code?

 公共抽象类DomainObjectBase
{
    保护布尔_isNew;
}
 

解决方案

从公共语言规范:

  

符合CLS的语言编译器必须遵循统一$ C $的技术报告15 C标准3.0,它支配的字符集,可启动并包含在标识符中的附件7的规则。该标准可从统一code联盟的网站。

如果您look这件事:

  word里下划线上内容怎么在下划线范围内居中

这是一个标识符的第一个字符可以是一个大写字母,小写字母,首字母大写字母,修饰符字母,其他的字母或字母数字。标识符的后续字符可以是任意的,加上非间距标记,间距组合标记,十进制数,连接器标点符号和格式codeS(如右 - 左 - 标记)。通常情况下,格式化codeS应存储或比较标识符之前被过滤掉。

基本上,你不能以下划线开头的标识符 - 这违反了符合CLS上的可见(公开/保护)字段

Why do I get the compiler warning

Identifier 'Logic.DomainObjectBase._isNew' is not CLS-compliant

for the following code?

public abstract class DomainObjectBase
{
    protected bool _isNew;
}

解决方案

From the Common Language Specification:

CLS-compliant language compilers must follow the rules of Annex 7 of Technical Report 15 of the Unicode Standard 3.0, which governs the set of characters that can start and be included in identifiers. This standard is available from the Web site of the Unicode Consortium.

If you look this up:

That is, the first character of an identifier can be an uppercase letter, lowercase letter, titlecase letter, modifier letter, other letter, or letter number. The subsequent characters of an identifier can be any of those, plus non-spacing marks, spacing combining marks, decimal numbers, connector punctuations, and formatting codes (such as right-left-mark). Normally the formatting codes should be filtered out before storing or comparing identifiers.

Basically, you can't start an identifier with an underscore - this violates CLS compliant on a visible (public/protected) field.