Property cung cấp quyền truy cập có kiểm soát vào private field thông qua get/set accessors, thực thi encapsulation.
- Field là biến member trực tiếp.
- Property cho phép validation, computed values và change notification.
- Luôn expose public state qua property chứ không phải field.
- Auto-property (
{ get; set; }) đơn giản hóa pattern phổ biến nhất.
Properties provide controlled access to private fields via get/set accessors, implementing encapsulation.
- Fields are direct member variables.
- Properties enable validation, computed values, and change notifications.
- Always expose public state through properties, not fields.
- Auto-properties (
{ get; set; }) simplify the most common patterns.