How do I set a property from within the class it is defined in?
Printable View
How do I set a property from within the class it is defined in?
Typically in the contructor you set the class's properties just like you were setting any other variable.
generally a property is the public exposure of some private field. This isn't always the case, but it is the most common.
So when you want to do what you are asking, you need to decide if you just want to set the backing field, or if you want to set the property which then sets the backing field. The difference being if the property set does any additional things, like fire a property changed event or something along those lines. Sometimes it is desirable to have this and sometimes it is not, it is all up to your code and what it is supposed to be doing.
So from within the class, you have the ability to bypass the property and just set the backing field to whatever value it needs to be set to.