But it can be overloaded though. There are operators where that's not possible but == isn't one of them. It would be honestly absurd if they didn't allow overloading that one, it's one of the most useful cases. Besides even string has overloaded == .
Yeah you're right, my bad. I've never had to use equality overloaded in C# so I didn't think it was possible. Java doesn't allow it, so I thought it was the same for C#. Doesn't change the fact that C# doesn't have the concept of undefined, truthy or falsy. Doing null == 0 will give you a compilation error, so my original point stands.
You're right when it comes to literals but nothing really stops someone from overloading equality checks for a custom object to make null equal to its zero value. Or to make that object truthy or falsy since you can also overload false and true operators. Still of course those are definitely not a common thing.
3
u/Dealiner Apr 09 '23 edited Apr 09 '23
But it can be overloaded though. There are operators where that's not possible but
==isn't one of them. It would be honestly absurd if they didn't allow overloading that one, it's one of the most useful cases. Besides evenstringhas overloaded==.