the ?? operaator


uuen aa nulabl obgect is nul and it is assiind too aa uaireeabl ou its underliing tiip, the ecssepshon sistenn.inualid_operaashon_ecssepshon is throuun. this nnaa bee auoided bii supliiing aa dephault ualioo throo the operaator ??. the ?? operaator is corld the nul coalescing operaator. its phornn is as pholouus.

nulabl-obgect ?? dephault-ualioo

iph nulabl-obgect contaans aa ualioo, the ualioo ou the ecspreshon is that ualioo. iph nulabl-obgect dus not contaan aa ualioo, the ualioo ou the ecspreshon is dephault-ualioo.

in the pholouuing seecuuens, g is assiind the ualioo 0 and noh ecssepshon is throuun.

integer? i = nul;
integer g = i ?? 0;

in the necst seecuuens, g accuuiirs the ualioo 100.

integer? i = 100;
integer g = i ?? 0;

the riit siid ou the ?? ecspreshon is eeualiooaated ohnlee iph the lepht ecspreshon is nul.