Export (0) Print
Expand All
Expand Minimize

Compiler Error CS0200

Property or indexer 'property' cannot be assigned to — it is read only

An attempt was made to assign a value to a property, but the property does not have a set accessor. Resolve the error by adding a set accessor.

The following sample generates CS0200:

// CS0200.cs
public class MainClass
{
   // private int _mi;
   int I
   {
      get
      {
         return 1;
      }

      // uncomment the set accessor and declaration for _mi
      /*
      set
      {
         _mi = value;
      }
      */
   }

   public static void Main ()
   {
      MainClass II = new MainClass();
      II.I = 9;   // CS0200
   }
}
Show:
© 2014 Microsoft