Maybe a stupid question, but..
In my code I use the following construction at several places.
void MyFunction()
{
DoSomething(myClass.myProperty)
myClass.PropertyChanged += (s,e ) => {
if (e.PropertyName == "myProperty") {
DoSomething(myClass.myProperty);
}
}
}
So I want to do something initially, and also do the same when the property changes in the future.
Now the thing is, MyFunction() gets called several time during my program's execution. Will the delegate I assign to PropertyChanged be added evertime it passes through this method? (consuming more memory every iteration and slowing down the program) Or is the compiler/runtime smart enough to understand I should be only added the first time..? And if so, how does this work?