3 ms·
> The is operator can't be overloaded, and always compiles to IL eq, whereas == can be overloaded in custom types. That's exactly the reason to use the opposit
by golergka 7y ago
> The is operator can't be overloaded, and always compiles to IL eq, whereas == can be overloaded in custom types.
That's exactly the reason to use the opposite. In certain C# environments (like Unity game engine) the == is overloaded in a very meaningful way (when C# objects are used as representations of unmanaged objects, and they appear to "equal null" if the represented object is no longer available in the system), and using methods other than == to compare to null (such as casting to boolean) can introduce hard to detect bugs.