views:

73

answers:

1

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
Hey David thanks for quick reply you think this makes the properties of class only set by the constructor
Srikrishna Sallam
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