我正在開發一個符合CLS的類型庫,並且在它內部有一個類,它包含私有的,受保護的和公共的字段和屬性。我使用下劃線符號(_)作爲私有或受保護字段的前綴,並使用小首字母來區分它們來自具有相同名稱的屬性。它看起來如此:什麼是符合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風格的前綴?
嗯......如何處理事件? – Vasya
@ Praetor12什麼*關於*事件?派生類需要訪問該領域的什麼?也許添加一個特定的事件相關的例子? –
是的。基類有一個事件,它由派生類方法調用。對於這樣的機制,我這樣做了: protected EventHandler _stateChanged; 公共事件EventHandler StateChanged; { add {lock(this.StateChanged){this._stateChanged + = value;刪除{lock(this.StateChanged){this._stateChanged - = value;}} remove { }} } –
Vasya