Null Coalescing Operator in C#.Net

Sign up for an Office 365 SharePoint Online Business Subscription

In this article, we will discuss C#.Net Null Coalescing operator. You can also check my previous posts on:
This is a binary operator which is helpful in case of Null values evaluation and is noted as ??
A ?? B
Here it means if A is not null then evaluate A else take the value of Y.
int? i = null;
int j = a.Value;
Here in the 2nd statement, it will give an exception because we are trung to get the value which is null.
So to avoid the situation we can use Null Coalescing Operator
int? i = null;
int j = a ?? 0;
Here it will not give any exception rather it will take 0 and assign it to j.
If a is not null then it will evaluate an else it will take the value provided in Null Coalescing Operator which is 0 in this example.

You May Also like the Following SharePoint Online Tutorials:

About Bijay Kumar

I am Bijay from Odisha, India. Currently working in my own venture TSInfo Technologies in Bangalore, India. I am Microsoft Office Servers and Services (SharePoint) MVP (5 times). I works in SharePoint 2016/2013/2010, SharePoint Online Office 365 etc. Check out My MVP Profile.. I also run popular SharePoint web site

View all posts by Bijay Kumar →