編譯器錯誤 CS0271
更新:2007 年 11 月
錯誤訊息
這個內容中不能使用屬性或索引子 'property/indexer',因為無法存取 get 存取子
當您嘗試存取無法存取的 get 存取子時,便會發生這個錯誤。若要解決這個錯誤,請增加存取子的存取範圍,或變更呼叫位置。如需詳細資訊,請參閱存取子存取範圍和屬性 (C# 程式設計手冊)。
下列範例會產生 CS0271:
// CS0271.cs
public class MyClass
{
public int Property
{
private get { return 0; }
set { }
}
public int Property2
{
get { return 0; }
set { }
}
}
public class Test
{
public static void Main(string[] args)
{
MyClass c = new MyClass();
int a = c.Property; // CS0271
int b = c.Property2; // OK
}
}