I am reading up on the changes introduced in C# 6.0 and I have a question about null operators.
In C# 6 this expression
int? x= y?.length;
will be valid if y is null and return a null. No NullargumentException will be raised. Which I believe is a good addition to the language. It removes extra checks and ugly looking code.
But in the case of the null conditional operator we might have code like the following
int? x= y?.length ?? 0;
If y is null then 0 is returned. What happens though if length is null? It returns zero again?
lengthwould beintso it will return 0y?.lengthis evaluted first. So: wheny?.lengthisnull, then(null ?? 0)evalutes to0. I'm not sure only if cast would bee needed:(int?)0lengthisintorint?. It looks to me that it isint?rather.