Peter

My feedback

  1. 6,013 votes
    Vote
    Sign in
    (thinking…)
    Sign in with: facebook google
    Signed in as (Sign out)
    You have left! (?) (thinking…)
    212 comments  ·  Visual Studio IDE » Languages - C#  ·  Flag idea as inappropriate…  ·  Admin →
    Peter 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
    if (myPointer)
    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#.

Feedback and Knowledge Base