Possible Duplicate:
What is the difference between a field and a property in C#?
i would like to know the difference between a variable and a property.can any one explain
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.
Simply you can’t validate the data being stored in variable but in a Property you can.
A Propery is more like a method as it has
get&setmethods which you define to handle the data.Also they are usefull in Databinding.
Properties expose fields. Fields should (almost always) be kept private to a class and accessed via get and set properties. Properties provide a level of abstraction allowing you to change the fields while not affecting the external way they are accessed by the things that use your class.
Example:
like in case of Date of Birth. You need to validate that age is less then todays date:
In a Field this is valid:
But in a property you can validate it: