Home          welcome : Guest          Log In      
  Xpode.com Beta version

Click here to Search Article

Categories/Articles

 

Null coalescing Operator (?? operator)

 

Submitted By:


Rohit kakria

Detail : I am software developer

Null coalescing Operator (?? operator) is used with nullable types and reference types. It is used to compare the values if there is an null value between two values. both values should be of same type e.g. integer. Null coalescing Operator (?? operator) compare the both values and return the first value if first value is not null. If first value is null then it will go for second value.

Example code is given below:

 int? i = null;
int? j = 10;

int k;
k = i ?? 20;

Response.Write("Result for k = i ?? 20 is " + k + "");

k = j ?? 30;

Response.Write("Result for k = j ?? 30 is " + k + "");

In this code we are taking the variable i which is null and j which having value is 10. Another variable is k which is using to get assigned the value.

k = i ?? 20;

in this line compiler will assign the value 20 to k if i is null.

k = j ?? 30;

in this vale of k is 10 because j is not empty. compiler will check the first value. if that is null the it will go to second value. Both values which we are comparing should be of same type e.g. integer







Comments
Share this article   |    Print   
Guest      Wednesday, May 12, 2010
Both values which we are comparing should be of same type e.g. integer<strong><A href=&quothttp://www.panjewellery.com/&;quot; target=_blank>pandora beads</A></strong> <strong><A href=&quothttp://www.panjewellery.com/&;quot; target=_blank>pandora bracelet</A></strong> <strong><A href=&quothttp://www.panjewellery.com/&;quot; target=_blank>pandora charm</A></strong> <strong><A href=&quothttp://www.panjewellery.com/&;quot; target=_blank>pandora chains</A></strong>
 
*  Name         *   Comments :ar 8) :cry: 8)
:shock: :shock: :evil: :!:
:( :idea: :lol: :x
:green: :| :question: :P
:oops: :roll: :) :o
:twisted: :wink:
*  Email          
                          (will not publish)
     
  Location           
  Website            
Enter the code *
(as shown below)