Null coalescing operator with method calls
suggest changeThe 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!";
Found a mistake? Have a question or improvement idea?
Let me know.
Table Of Contents