Coalesce ?? operator in C# 2.0

Posted by Dmytro Shteflyuk on under ASP.NET

Operator ??, that was introduced in the .NET 2.0, takes first place in my top used C# idioms list a long time, but unfortunately it is rarely used in projects I’ve participated. Therefore these snippets could be found in production code very often:

1
2
3
4
5
public string Caption
{
    get { return ViewState["Caption"] != null ? (string) ViewState["Caption"] : ""; }
    set { ViewState["Caption"] = value; }
}

Read the rest of entry »