readonly field can be initialized either at the declaration or in a constructor.‘
data-guid="257637d5ffda9953f70ee09ecc32366c">readonly 字段可以在聲明或構造函數中初始化。
class Age
{
readonly int age;
public
Age()
age = 10;
}
public void
ChangeAge()
//age = 100;//嘗試修改age的值,錯誤
以下是可以進行的[集合類型不同于普通變量]
class ChuckReadOnly<TKey,TValue>
private readonly
Dictionary<TKey, TValue> dictinonary = new Dictionary<TKey,
TValue>();
public void DoTask(TKey key,TValue value)
dictinonary.Add(key,value);
readony主要是監控"="指派運算的