Get-Set Properties
Let's learn about the get-set properties of a class.
What is the get-set property?
Fields within classes should generally be private and only allow access when needed. This is where the get-set property accessors, get
or set
, are used to access or change data. The get-set properties combine aspects of both fields and methods.
Syntax
private string myProperty; // Declare a private field
public string MyProperty // Property is Public: it can be accessed from outside the class
{
get { return myProperty; } // Get retrieves the
...