c# - 为什么这个带下划线的名称不符合 CLS?

标签 c# .net cls-compliant

为什么我会收到编译器警告

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

对于下面的代码?

public abstract class DomainObjectBase
{
    protected bool _isNew;
}

最佳答案

来自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.

如果你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.

基本上,您不能以下划线开头标识符 - 这违反了可见(公共(public)/ protected )字段上的 CLS 合规性。

关于c# - 为什么这个带下划线的名称不符合 CLS?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/1195030/

相关文章:

c# - 为什么我无法捕获返回类型为 void 的异步函数中的异常?

c# - 打开小型转储 : No native symbols in symbol file

c# - Entity Framework 、SQLite 和延迟加载

c# - 为什么这个 CLS 不兼容?

c# - 在屏幕上摇动表格

c# - 如何复制现有列并将其插入到datagrid中?

c# - 在设计时代码中使用模拟框架的缺点

php - SOAP 错误 : Encoding: object hasn't 'first_name' property

c#-6.0 - 如何在符合 CLS 的程序集中使用 CallerMemberName