Communities for your favorite technologies. Explore all Collectives
Stack Overflow for Teams is now called Stack Internal. Bring the best of human thought and AI automation together at your work.
Bring the best of human thought and AI automation together at your work. Learn more
Find centralized, trusted content and collaborate around the technologies you use most.
Stack Internal
Knowledge at work
Bring the best of human thought and AI automation together at your work.
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 a comment
I think you'll have to go back to doing your property the old fashioned way.
private string _PropertyA; public string propertyA { get { return _PropertyA; } set { _PropertyA=value; //Set other parameter } }
Expand out the property setter and assign the other property.
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.
Required, but never shown
By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.
Start asking to get answers
Find the answer to your question by asking.
Explore related questions
See similar questions with these tags.