With this, you can perform some code in the get
or set
scope.
private string _myProperty;
public string myProperty
{
get { return _myProperty; }
set { _myProperty = value; }
}
You also can use automatic properties:
public string myProperty
{
get;
set;
}
And .Net Framework will manage for you. It was create because it is a good pratice and make it easy to do.
You also can control the visibility of these scopes, for sample:
public string myProperty
{
get;
private set;
}
public string myProperty2
{
get;
protected set;
}
public string myProperty3
{
get;
}
Now in C# you can initialize the value of a property. For sample:
public int Property { get; set; } = 1;
If also can define it and make it readonly, without a set.
public int Property { get; } = 1;
And finally, you can define an arrow function.
public int Property => GetValue();