Saturday, September 7, 2013

How to restrict get; setter; to get only inside c# asp net classes

Lets say you have a get, set property inside a class say IP
public String IP { get; }
 
When I specify get only I wont be able to set the property even inside the class itself. e.g
this.IP = "127.0.0.1";
Property or indexer 'IP' cannot be assigned to -- it is readonly 
Solution, just type private keyword with set property like this
public String IP { getprivate set; }
All done

No comments:

Post a Comment