Hi , I am trying to make the properties of class which can only be set through the constructor of the same class
+1
A:
Make the properties have readonly backing fields:
public class Thing
{
private readonly string _value;
public Thing(string value)
{
_value = value;
}
public string Value { get { return _value; } }
}
David Morton
2010-03-01 16:58:58
Hey David thanks for quick reply you think this makes the properties of class only set by the constructor
Srikrishna Sallam
2010-03-01 17:04:03
Yes it does. If you're using C#, please update your tags on your original post to be more clear. This answer is assuming you're using C#. If you're not, again, please add a tag with the programming language you're using, so that people can understand the question more clearly.
David Morton
2010-03-01 17:09:22