Possible Duplicate:
What is the difference between a field and a property in C#
Can someone explain the diffrence if any between these two properties?
public string City { get; set; }
public string City;
Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.
Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
Please briefly explain why you feel this question should be reported.
Please briefly explain why you feel this answer should be reported.
Please briefly explain why you feel this user should be reported.
The first one is an actual property. The second one is just a field.
Generally speaking, fields should be kept
privateand are what store actual data. Properties don’t actually store any data, but they point to fields. In the case of the auto-property above, it will auto-generate a hidden field like _city behind the scenes to hold the data.Hope this helps!