为什么这个名字用下划线不符合CLS? [英] Why is this name with an underscore not CLS Compliant?

查看:630
本文介绍了为什么这个名字用下划线不符合CLS?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

  

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

以下code?

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

解决方案

公共语言规范

  

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

如果您look这件事

  

这是一个标识符的第一个字符可以是一个大写字母,小写字母,首字母大写字母,修饰符字母,其他的字母或字母数字。标识符的后续字符可以是任意的,加上非间距标记,间距组合标记,十进制数,连接器标点符号和格式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.

这篇关于为什么这个名字用下划线不符合CLS?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆