Null coalescing operator with method calls C# with Example



Null coalescing operator with method calls C# with 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!"; 

0 Comment's

Comment Form

Submit Comment