Skip to main content

Expand Null Coalescing Operation (C#)

Converts a null coalescing operation to an equivalent ternary expression.

#Availability

Available from the context menu or via shortcuts:

  • when the edit cursor, or caret is on a statement that uses the ?? operator.

#Notes

#Example

private string GetMessage(string text)
{
    return (text ?? "null");
}

Result:

private string GetMessage(string text)
{
    return (text != null ? text : "null");
}

#Screenshot

rsExpandNullCoalescingOperation

See Also