Hacker News new | past | comments | ask | show | jobs | submit login

a number of the C# lang developers prefer (x is object) for the latter, FWIW.



Yep, looking at the IL they are equivalent. And it definitely makes code prettier due to reduced parentheses. This is also true for generics.

Doing (x != null), !(x is null), or (x is object) all become:

    ldloc.s
    ldnull
    cgt.un
    stloc.s


why not add an operator so you can say (x !is null)?


Largely because (x is null) is a silly workaround to an uncommon and easily avoided problem (bad operator overloading).




Guidelines | FAQ | Lists | API | Security | Legal | Apply to YC | Contact

Search: