C# Properties
C# Properties:
Properties are a feature of C# that are designed to support Encapsulation.
"A property is a member that provides a flexible mechanism to read, write, or compute the value of a private field. Properties can be used as if they are public data members, but they are actually special methods called accessors. This enables data to be accessed easily and still helps promote the safety and flexibility of methods." MSDN
Properties are public fields that function to provide a public interface for controlled access to the hidden fields value.
In the example below, we have a private variable: name. A public Property: Name is used for accessing the private variable, through accessor methods: get and set.
Properties Hide Class Implementation Details
Last updated