4 ms·
a number of the C# lang developers prefer (x is object) for the latter, FWIW.
by Serow225 7y ago
a number of the C# lang developers prefer (x is object) for the latter, FWIW.
- eyegor 7y agoYep, 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
- earenndil 7y agowhy not add an operator so you can say (x !is null)?
- gregoryl 7y agoLargely because (x is null) is a silly workaround to an uncommon and easily avoided problem (bad operator overloading).