I have a property that is assigned as:
public string propertyA{get;set;}
I want to call a method automatically when this property is set to assign another property in the class. Best way to trigger the call?
I have a property that is assigned as:
public string propertyA{get;set;}
I want to call a method automatically when this property is set to assign another property in the class. Best way to trigger the call?
You don't have to use that syntax that is just shorthand. If you expand it you can do whatever you like in the setter.
public string PropertyA
{
get { return a; }
set
{
a = value;
doStuff();
}
}
Add the backing field manually and provide some code to do what you want in the settor.
private string propertyA;
public string PropertyA
{
get { return this.propertyA; }
set
{
this.propertyA = value;
this.propertyB = value + "B";
}
}
Define the setter.
Inside it either trigger an event or directly assign the other property.