【发布时间】:2011-09-27 10:12:57
【问题描述】:
我正在开发一个符合 CLS 的类型库,其中有一个类,其中包含私有、受保护和公共字段和属性。我使用下划线符号 (_) 作为私有或受保护字段的前缀,并使用小首字母将它们与具有相同名称的属性区分开来。看起来是这样的:
class SomeClass
{
private int _age; //Here is OK
public int Age { get { return this._get; } }
}
但是当我尝试使用受保护的字段时,我遇到了下一个问题:
class SomeClass
{
protected int _age; //Here is NOT CLS-compliant (because of _ can't be the first symbol of identifier)
public int Age { get { return this._get; } }
}
然后我尝试这样做:
class SomeClass
{
protected int age; //Here is NOT CLS-compliant (because of age and Age differ only in one symbol)
public int Age { get { return this._get; } }
}
请告诉我,在这种情况下,开发人员之间的正确 CLS 兼容表示法或约定是什么?我可以使用 l_age 等 C 风格的前缀吗?
【问题讨论】:
标签: c# .net naming-conventions