In C#, ?? exploitant staat bekend als Null-coalescerende operator. Het retourneert de waarde van de linker operand als deze niet nul is. Als deze nul is, wordt de rechter operand geƫvalueerd en wordt het resultaat geretourneerd. Of als de linkeroperand niet-nul oplevert, evalueert hij de rechteroperand niet.
Syntaxis:
p ?? q>
Hier is p de linker en q de rechter operand van ?? exploitant. De waarde van p kan van het null-type zijn, maar de waarde van q moet van het niet-null-type zijn. Als de waarde van p nul is, retourneert deze de waarde van q. Anders retourneert het de waarde van p.
Belangrijke punten:
- De ?? operator wordt gebruikt om nulwaarden te controleren en u kunt ook een standaardwaarde toewijzen aan een variabele waarvan de waarde null is (of een null-type).
- Je mag niet overbelasten ?? exploitant.
- Het is rechtsassociatief.
- In ?? operator, kunt u de expressie throw gebruiken als een rechteroperand van ?? operator die uw code beknopter maakt.
- U mag gebruik maken van ?? operator met waardetypen en referentietypen.Voorbeeld: 
 
 Java splitst de tekenreeks op door een scheidingsteken 
 
 
 
 
 // C# program to illustrate how to use>// ?? operator with value types and>// reference types>using>System;>>namespace>example {>>class>Program {>>static>void>Main(>string>[] args)>>{>>>// Reference types>>string>item_1 =>null>;>>string>item_2 =>'techcodeview.com'>;>>string>item_3 =>'GFG'>;>>>string>item_4 = item_1 ?? item_2;>>item_3 = item_4 ?? item_2;>>>Console.WriteLine(>'Value of item_4 is: {0} '>+>>'Value of item_3 is: {1}'>, item_4, item_3);>>>// Value types>>int>? item_5 =>null>;>>>Program obj =>new>Program();>>>// Using ?? operator assigns>>// the value of a value type>>// and also you are allowed>>// to use method with ?? operator>>int>? item_6 = item_5 ?? obj.Add(10, 30);>>Console.WriteLine(>'Value of item_6 is: {0}'>, item_6);>>}>>>// Method>>public>int>Add(>int>a,>int>b)>>{>>int>result = a + b;>>return>result;>>}>}>}>> > Uitgang: Value of item_4 is: techcodeview.com Value of item_3 is: techcodeview.com Value of item_6 is: 40> 
- Met de hulp van ?? exploitant die u kunt voorkomen OngeldigeOperatieException .Voorbeeld: 
 
 
 // C# program to illustrate how ??>// operator prevent the>// InvalidOperationException>using>System;>>namespace>example {>>class>GFG {>>>// Main Method>>static>void>Main(>string>[] args)>>{>>// Creating items of nullable types>>int>? item_1 =>null>;>>>/*>>Here if you use this commented part,>>then this statement will give you an>>InvalidOperationException. So to>>overcome this problem we use ?? operator>>int? item_2 = item_1.Value;>>*/>>>// With the help of ?? operator we>>// assign a default value to the item_2>>// And the value of item_1 is null.>>int>? item_2 = item_1 ?? 100;>>Console.WriteLine(>'Value of item_1 is: {0}'>, item_1);>>Console.WriteLine(>'Value of item_2 is: {0}'>, item_2);>>}>}>}>> > Uitgang: Value of item_1 is: Value of item_2 is: 100> 
- Met de hulp van ?? operator kunt u veel overbodige if-else-voorwaarden verwijderen en uw code compact en leesbaar maken.Voorbeeld: 
 
 
 // C# program to illustrate how ??>// operator replaces if-else statements>using>System;>>namespace>example {>>class>GFG {>>>// Main Method>>static>void>Main(>string>[] args)>>{>>// Creating items of nullable types>>int>? item_1 =>null>;>>>int>? item_2;>>>if>(item_1.HasValue) {>>item_2 = item_1;>>}>>else>{>>item_2 = 200;>>}>>Console.WriteLine(>'Value of item_1 is: {0}'>, item_1);>>Console.WriteLine(>'Value of item_2 is: {0}'>, item_2);>>}>}>}>> > Uitgang: Value of item_1 is: Value of item_2 is: 200> 
 
 
 // C# program to illustrate how ??>// operator replaces if-else statements>using>System;>>namespace>example {>>class>GFG {>>>// Main Method>>static>void>Main(>string>[] args)>>{>>// Creating items of nullable types>>int>? item_1 =>null>;>>>// Using ?? operator>>int>? item_2 = item_1 ?? 200;>>Console.WriteLine(>'Value of item_1 is: {0}'>, item_1);>>Console.WriteLine(>'Value of item_2 is: {0}'>, item_2);>>}>}>}>> > Uitgang: Value of item_1 is: Value of item_2 is: 200> 
- ?? operator kan worden genest. Het maakt uw code leesbaarder en vermindert ook meerdere if-else voorwaarden.Voorbeeld: 
 Java onveranderlijke lijst 
 
 // C# program to illustrate how>// we use nested ?? operator>using>System;>>namespace>example {>>class>GFG {>>>// Main Method>>static>void>Main(>string>[] args)>>{>>// Creating items of nullable types>>int>? item_1 =>null>;>>int>? item_2 =>null>;>>int>? item_3 = 500;>>>// Nested ?? operator>>int>? item_4 = item_1 ?? item_2 ?? item_3;>>>Console.WriteLine(>'Value of item_4 is: {0} '>, item_4);>>}>}>}>> > Uitgang: Value of item_4 is: 500> 
