컴파일러 오류 CS0271

업데이트: 2007년 11월

오류 메시지

get 접근자에 액세스할 수 없으므로 'property/indexer' 속성 또는 인덱서는 이 컨텍스트에서 사용할 수 없습니다.
The property or indexer 'property/indexer' cannot be used in this context because the get accessor is inaccessible

이 오류는 액세스할 수 없는 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
   }
}