I originally took it from this address: http://csharpindepth.com/articles/chapter8/propertiesmatter.aspx and for some reason I could not get my head around it. Can somebody explain me why Console.WriteLine(holder.Property.Value); outputs 0.
void Main()
{
MutableStructHolder holder = new MutableStructHolder();
holder.Field.SetValue(10);
holder.Property.SetValue(10);
Console.WriteLine(holder.Field.Value); // Outputs 10
Console.WriteLine(holder.Property.Value); // Outputs 0
}
struct MutableStruct
{
public int Value { get; set; }
public void SetValue(int newValue)
{
Value = newValue;
}
}
class MutableStructHolder
{
public MutableStruct Field;
public MutableStruct Property { get; set; }
}