I have this in my code:
SelectList(blah, \"blah\", \"blah\", cu.Customer.CustomerID.ToString())
It gives a error when it returns null, how
(C# 2.0 - C# 5.0)
The ternary operator works, but if you want even shorter expression working on arbitrary objects you can use:
(myObject ?? "").ToString()
Here is real-life example from my code:
private HtmlTableCell CreateTableCell(object cellContents)
{
return new HtmlTableCell()
{
InnerText = (cellContents ?? "").ToString()
};
}