I am having a hard time understanding how nullable value types works in C#9.
Following documentation from:
I can write (no compiler error):
int? a = 10;
a++; // No need for explicit 'a.Value'
But I cannot write (compiler error):
Span<char> TryFormatOrNull(int? input)
{
char[] buffer = new char[512];
if (input == null) return null;
_ = input.TryFormat(buffer, out _);
return buffer;
}
I need to write (no syntaxic sugar):
Span<char> TryFormatOrNull(int? input)
{
char[] buffer = new char[512];
if (input == null) return null;
_ = input.Value.TryFormat(buffer, out _);
return buffer;
}
What did I misunderstood with nullable value types vs member function/operator ?