C# and .NET interview questions on Coalescing operator.
When should we use "??" (NULL Coalescing operator) ?
"??" is a NULL coalescing operator. If you see the English meaning of coalescing it says "consolidate together". Coalescing operator returns the first NON-NULL value from a chain. For example below is a simple coalescing code which chains four strings.
So if "str1" is null it will try "str2" , if "str2" is null it will try "str3" and so on until it finds a string with a non-null value.
What is the benefit of coalescing?
You do not need to write long if condition as shown below.
Do not forget to watch below C#(CSharp) interview questions and answers series :-