Example of Null Coalescing Operator

Amatya
Posted by Amatya under C# category on | Points: 40 | Views : 714
Example of Null Coalescing Operator -> If the value of first operand is null, then the operator returns the value of the second operand, otherwise
it returns the value of the first operand.


double? dnf1 = null;
double? dnf2 = 1.18;
double? dnf3;
dnf3 = dnf1 ?? 2.16;
Console.WriteLine("Value of dnf3", dnf3);
dnf3 = dnf2 ?? 2.16; //null coalesing operator
Console.WriteLine("dnf3:", dnf3);



Output:
Value of dnf3 2.16
dnf3:1.18

Comments or Responses

Login to post response