編譯器錯誤 CS1650
更新:2007 年 11 月
錯誤訊息
無法對靜態唯讀欄位 'identifier' 的欄位進行指派 (除非在靜態建構函式或變數初始設定式)
當您嘗試修改不允許修改的唯讀靜態欄位的成員時,便會發生這個錯誤。若要解決這個錯誤,請將唯讀欄位的設定限於建構函式或變數初始設定式,或從欄位的宣告中移除 readonly 關鍵字。
// CS1650.cs
public struct Inner
{
public int i;
}
class Outer
{
public static readonly Inner inner = new Inner();
}
class D
{
static void Main()
{
Outer.inner.i = 1; // CS1650
}
}