Expand Minimize
This topic has not yet been rated - Rate this topic

Compiler Error CS0271

The property or indexer 'property/indexer' cannot be used in this context because the get accessor is inaccessible

This error occurs when you try to access an inaccessible get accessor. To resolve this error, increase the accessibility of the accessor, or change the calling location. For more information, see Accessor Accessibility and Properties (C# Programming Guide).

The following example generates 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
   }
}
Did you find this helpful?
(1500 characters remaining)

Community Additions

ADD
© 2013 Microsoft. All rights reserved.