Edit

Share via


Compiler Error CS0154

The property or indexer 'property' cannot be used in this context because it lacks the get accessor

An attempt to use a property failed because no get accessor method was defined in the property. For more information, see Fields.

Example

The following sample generates CS0154:

// CS0154.cs  
public class MyClass2  
{  
    public int i  
    {  
        set  
        {  
        }  
        // uncomment the get method to resolve this error  
        /*  
        get  
        {  
            return 0;  
        }  
        */  
    }  
}  
  
public class MyClass  
{  
    public static void Main()  
    {  
        MyClass2 myClass2 = new MyClass2();  
        int j = myClass2.i;   // CS0154, no get method  
    }  
}