Suppose I have
class A
{
public List<B> LiProperty
{
get;
set { //will I get called when someone calls A::LiProperty.Add()? }
}
}
Then
A a = new A();
a.LiProperty.Add(new B());
Will the mutator ever be called?
My instincts say that get is returning a pointer to the list so the add method is being called directly on the object, but then again C# does some funky stuff sometimes with immutable types. Anybody know the answer for certain?
Changing the property is to change it to point to another different
List<T>. Adding an object to the list is not changing whichList<T>the property points to. The code will not call the setter unless you wrotea.LiProperty = new List<T>();