With Unity5 (it's hard to know exactly what version of c#/Mono/.Net is being used), we do properties exactly like this:
private int _distance;
public int Distance
{
private set
{
_distance = value;
controls.Blahblah(_distance);
}
get
{
Debug.Log("hah!);
return _distance;
}
}
But consider the new "automatic properties" in c#, which seem to be like
public int Distance {get; set;} // ?
but I don't know how to "do something" in the getter/setter ??
Or in other words, is there a way to auto generate the backing variable (as well as the convenience -- to keep it private) when "manually" making a Property?
To repeat since this was marked as a duplicate, how can I "do stuff" in the automatic Property idiom during the getter/setter ...
... or conversely ...
how to hide, get rid of, or automatically supply the backer if you write your own "manual" properties?
Note that of course you or another programmer can accidentally touch the _underscore backing variable: is there any way at all to avoid that??