更新:2007 年 11 月
错误消息
由于无法访问 set 访问器,属性或索引器“property/indexer”不能在此上下文中使用
当 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.
}
}