gpt4 book ai didi

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

转载 作者:IT王子 更新时间:2023-10-29 03:47:39 29 4
gpt4 key购买 nike

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

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/

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