Explain Coalescing operator (??) in C# ? C# and .NET interview questions with answers

Posted by Questpond under C# category on | Points: 350 | Views : 6527
"??" 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.

string final =str1 ?? str2 ?? str3 ?? str4;



Get Questpond videos on discounted price from ITFunda.com.

Comments or Responses

Login to post response