I'm not sure what the difference is between these two statements, I always thought that you used properties if you need additional get / set logic?
In the first case, the compiler will automatically add a field to you and wrap it. This is basically equivalent to:
private string forename; public string Forename { get { return this.forename; } set { this.forename = value; } }
There are many advantages to using properties over fields. Even if you donβt need some specific reasons, such as data binding, it helps the future API.
The main problem is that if you create a field, but in v2 of your application, you need a property, you will break the API. Using the automatic property up, you can change your API at any time without fear of problems with the original or binary compatibility.
Reed Copsey Aug 18 '09 at 15:37 2009-08-18 15:37
source share