?? Operator in C# and its usage

By Santhosh N

This explains the C# Operator, ?? and its usage

C# Operator, ?? is called as null-coalescing operator. This is used to define a default value for both nullable value types and reference types.

EX:
int? i = null;
int j = (i ?? -1);

Here in the code, to assign a value of i, which is a nullable int type to j, which is int type, directly its not possible as both are different.
For this, to pass a default value when no value is present in i, ?? operator is used to specify the default value.
ie, when i is null, -1 is assigned to j

Related FAQs

Oracle provides a simple function to find and replace null values with the predefined values in select statements
This is how you can check if the given string is in numeric format or not in c#
This is a way to check if the given string is in numeric format or not
?? Operator in C# and its usage  (700 Views)