C# Language Null coalescing operator with method calls


Example

The null coalescing operator makes it easy to ensure that a method that may return null will fall back to a default value.

Without the null coalescing operator:

string name = GetName();

if (name == null)
    name = "Unknown!";

With the null coalescing operator:

string name = GetName() ?? "Unknown!";