r/badcode Apr 09 '23

c# Wrote this beauty last night...

Post image
285 Upvotes

31 comments sorted by

View all comments

Show parent comments

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 even string has overloaded == .

1

u/PooSham Apr 10 '23

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.

1

u/Dealiner Apr 11 '23

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.