Answer the question
In order to leave comments, you need to log in
Answer the question
In order to leave comments, you need to log in
1. If you need to restrict access to data for writing or reading, then properties
2. If you need easier access through reflection, then properties
3. If you implement an interface, then properties
In other cases, it doesn’t matter what you prefer.
.NET Framework General Reference -> Class Library Design Guide -> Member
Development Rules Field
Development Property Development
In fact, you will always use margins!
Properties are simply field accessors that look like fields.
If the field is not readonly or const, then in order to comply with encapsulation, they must be made private, and getters and setters should be used to access them. Properties simply provide syntactic sugar for easy implementation of the latter.
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question