I think it was in .net 2.0, microsoft introduced an accessor that was abbreviated to something like
public string Name { get; set; }
But is there any real difference between the above code, and simply:
public string Name;
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 main difference is that if you later need to add logic into your getter or setter, and other DLLs have already been compiled against yours, you can easily change
into
and it won’t be a breaking change to publish your new DLL and have other DLLs not be recompiled.
Whereas if you changed
into
then you’ll need to make sure any DLLs that use yours are recompiled, since they change from accessing a field into accessing a property.
This is obviously a bigger problem when you’re shipping DLLs to other programmers (as an open source project or as a component vendor for example) than if you’re just building an app for your own self / employer