Using ReSharper 7.1.1 in Visual Studio 2012. Sample code:
private string _str;
private string TheString
{
get
{
if (_str == null) // "X"
{
_str = GetString();
}
return _str;
}
}
// do some work to get string. e.g. read from database
private string GetString()
{
return "blah";
}
At the line marked "X", ReSharper underlines the "if" statement and suggests "Convert to ?? expression". But how? Am I missing something?
Given your code,
Click on the 'if' where its saying it wants to use the ??
press ALT-ENTER
or click on the lightbulb
it will then have an option to convert, either press enter, or click on it with the mouse and you will get
private string _str;
private string TheString
{
get { return _str ?? (_str = GetString()); }
}
Keith pretty much answered your question. Here's the screenshot of the light blub:
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With