Okay, I have done some thinking and testing. This is what happens:
int value = nullableInt?.Value;
Gives this error message when compiling:
Type 'int' does not contain a definition for `Value'
That means that ?
'converts' the int?
into the actual int
value. This is effectively the same as:
int value = nullableInt ?? default(int);
The result is an integer, which doesn't have a Value
, obviously.
Okay, might this help?
int value = nullableInt?;
No, that syntax isn't allowed.
So what then? Just keep using .GetValueOrDefault()
for this case.
int value = nullableInt.GetValueOrDefault();
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…