Possible Duplicate:
C#: Public Fields versus Automatic Properties
Do I need to use { get; set; } with c# fields that have no special actions when getting and setting
Consider these two options:
public int Foo { get; set; }
public int Foo;
They seem to be semantically equivalent, and I believe they will even compile to the same IL. So what is the advantage of using the property? Seeing a public field makes me feel uneasy, but I can't think of any concrete advantage to using the property syntax instead. If an explicit getter and setter are required in the future, public int Foo;
can be replaced by public int Foo { ... }
with no other changes necessary. The best I can come up with is that the property syntax just feels better, but I can hardly use this reason to convince someone else.
What is the advantage (if any) of using the property syntax in this case?