Thursday 18 February 2016

Property or indexer cannot be assigned to -- it is read only

Property or indexer 'Abc.Display' cannot be assigned to -- it is read only
==========================================================================

I get this Exception because in business class I had given only get accessor to the property of class as below:


class Abc
{
  public bool Display
  {
         get;         // i.e., it only can read the value, but cannot take any value
  }
}


now

Abc obj1= new Abc();
obj1.Display=true;   // here i am assinging value to the property as the property is read only

So that the error is coming and as in Business object we had given only 'get' accessor

now i had changed the property in Abc class as get and set as below :


class Abc
{
  public bool Display
  {
         get;         // i.e., it only can read the value, but cannot take any value
         set;
  }
}

now

Abc obj1= new Abc();
obj1.Display=true;

Now its well and good and not showing any error

No comments:

Post a Comment

Note: only a member of this blog may post a comment.