Test if a Property is not Null before Returning
- by DaveDev
I have the following property
public MyType MyProperty {get;set;}
I want to change this property so that if the value is null, it'll do populate the value first, and then return it... but without using a private member variable.
For instance, if I was doing this:
public MyType MyProperty
{
get
{
if (_myProperty != null)
return _myProperty
else
_myProperty = XYZ;
return _myProperty;
}
set
{
_myProperty = value;
}
}
is this possible? Or do I need the member variable to get it done?