Reading a lot about the Null propagation operator ?.
, I found no answer whether it is helpful in the following scenario.
Code that throws:
int[] values = null;
foreach ( var i in values ) // Throws since values is null.
{
// ...
}
To make this working, I have to add a null
check before access to the values
variable.
Most likely the above code is out of scope of the design considerations for the Null propagation operator. Still, to be sure, I have to ask.
My question:
Is the Null propagation operator helpful when trying to access null
collections in a foreach
loop?