編譯器錯誤 CS0272
更新:2007 年 11 月
錯誤訊息
這個內容中不能使用屬性或索引子 'property/indexer',因為無法存取 set 存取子
程式碼無法存取 set 存取子時,便會發生這個錯誤。若要解決這個錯誤,請增加存取子的存取範圍,或變更呼叫位置。如需詳細資訊,請參閱非對稱存取子的存取範圍 (C# 程式設計手冊)。
範例
下列範例會產生 CS0272:
// CS0272.cs
public class MyClass
{
public int Property
{
get { return 0; }
private set { }
}
}
public class Test
{
static void Main()
{
MyClass c = new MyClass();
c.Property = 10; // CS0272
// To resolve, remove the previous line
// or use an appropriate modifier on the set accessor.
}
}