In the June 24th C# Language Design Meeting, Microsoft made a subtle change to the parameter null checking syntax. By changing it from Type parameterName! to Type parameterName!! they effectively introduced a new ‘null check operator’.

This eliminates the problem of the single-bang having two similar, but opposite meanings.

void MethodA(string a!)

string a = b!;

In the above example, a! would mean “verify this isn’t null” while b! means “assume this isn’t null without checking”.

Before settling on the double-bang, there were other contenders for the syntax.

void M(string param!)
void M(string param!!)
void M(string! param)
void M(string !param)
void M(checked string param)
void M(string param ?? throw)
void M(string param is not null)
void M(notnull string param)
void M(null checked string param)
void M(bikeshed string param)
void M([NullChecked("Helper")] string param)
/* contract precondition forms */
void M(string param) Requires.NotNull(param)
void M(string param) when param is not null

For those wondering about the ‘bikeshed’ keyword, it refers to Parkinson’s Law of Triviality where in a committee is likely to focus the majority of their attention on minor details, say the bike shed outside of a nuclear reactor, while ignoring the hard questions such as which reactor core to use. One has to assume the note-taker for the June 17 C# Language Design Meeting was getting a bit frustrated.

For the C# 9 timeframe, the null check operator (!!) will still only be applicable to parameters. But developers and language designers are already speculating on where else it could be used.

#.net #language design #development #csharp #programming-c

C# Futures: Null Check Operator
1.30 GEEK