Hi all we can assign a value or return a value many other way.. so sometimes we are doing by properties(get,set).. can any one tell me main use of properties..
thanks
saj
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.
Properties encapsulate internal logic. They are the public interface and allow you to check values, apply rules and enable to change internal implementation.
This is in contrast to exposing internals directly.
For example:
Is better implemented:
You can now change the internal
myFieldand not affect other code outside the class. You can add logic to the setter, to the getter and more.If you don’t have any logic associated with member access, you can use automatic properties:
The compiler will generate a backing field automatically.