6,013 votesPeter commented
Maybe I'm oversimplifying things, but IMHO this could be done using an attribute to parameters:
void MyMethod([NotNull] string myParam)
If the Compiler sees thiis, it injects something like
if (value == null)
throw new ArgumentNullException(nameof(value));
Or even less verbs, by using something like the (string! myParam) the other poster proposed below.
And I also would like to see some simple null check. In C++ I can just werite
for null checks. In C# I always have to write
if (myRef == null)
That's the only thing I don't like about C#: It is very verbose and needs a lot of code for simple things. Just look at Swift and how much less code it requires to express the same thing compared to C#.