Massimo Caliman
Massimo Caliman
~1 min read

Modified

Categories

  • Computer Science

Tags

  • C#
  • Java

Languages

  • English

In C# the ?? operator is called the null-coalescing operator. Here’s an example of use:

string result = leftHand ?? rightHand ;

It returns the left-hand operand if it is not null, otherwise it returns the right-hand operand. A possible alternative in Java of C# ?? use ? , the ternary operator, like this:

String result = leftHand != null ? leftHand : rightHand; 

Or, by using a method like this:

String nullCoalescingOperator(String leftHand, String rightHand) {
    return leftHand != null ? leftHand : rightHand;
}