You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
MyProperty.get() returns a hidden backing store. Modifying the get() and set() methods of a property is a common practice. However, doing so requires that we declare a new backing store:
private int myVar;
public int MyProperty
{
get { return myVar; }
set { myVar = value; }
}
Rarely, if ever, will the backing store be directly accessed through code in a way that adds any additional functionality when the access modifier is private. How about exposing the hidden field of a property with the keyword field , to avoid writing unnecessary code when modifying the get() and set() of a property?
public int MyProperty
{
get { return field; }
set { field = value; }
}
Modified properties are declared often enough that this should warrant some quicker and cleaner alternatives, right?
The text was updated successfully, but these errors were encountered:
Problem
Consider the following auto-property:
MyProperty.get() returns a hidden backing store. Modifying the get() and set() methods of a property is a common practice. However, doing so requires that we declare a new backing store:
Rarely, if ever, will the backing store be directly accessed through code in a way that adds any additional functionality when the access modifier is private. How about exposing the hidden field of a property with the keyword
field
, to avoid writing unnecessary code when modifying the get() and set() of a property?Modified properties are declared often enough that this should warrant some quicker and cleaner alternatives, right?
The text was updated successfully, but these errors were encountered: