I currently have code that looks like this
private string _stringField;
protected string StringField
{
get
{
if (_stringField == null)
_stringField = GetStringField();
return _stringField;
}
}
ReSharper is suggesting I change the property to:
protected string StringField
{
get
{
return _stringField ?? (_stringField = GetStringField());
}
}
This isn't an idiom I've seen before and probably would have to think about the first time I saw it; is this something I should be concerned would confuse other people too?
Lazy<T>
, I still tend to use this approach in most cases. Choose whichever feels simpler to you and don't worry about confusing other people. I totally agree with @dreza here: That piece of code is clear enough for someone who saw something like that for the first time to get it in one minute. \$\endgroup\$