共用方式為


編譯器錯誤 CS0273

更新:2007 年 11 月

錯誤訊息

'property_accessor' 存取子的存取範圍修飾詞必須比屬性或索引子 'property' 更嚴格

set/get 存取子的存取範圍修飾詞必須比屬性或索引子 'property/indexer' 更嚴格

當您宣告屬性 (Property) 或索引子 (Indexer) 時,如果使用的存取修飾詞 (Modifier) 比其存取子 (Accessor) 的存取修飾詞限制更少,便會發生這個錯誤。若要解決這個錯誤,請在屬性或 set 存取子上使用適當的存取修飾詞。如需詳細資訊,請參閱存取子存取範圍

範例

這個範例包含具有內部 set 方法的內部屬性。下列範例會產生 CS0273。

// CS0273.cs
// compile with: /target:library
public class MyClass
{
   internal int Property
   {
      get { return 0; }
      internal set {}   // CS0273
      // try the following line instead
      // private set {}
   }
}