Can I overload the == operator? If yes how? | Sololearn: Learn to code for FREE!
New course! Every coder should learn Generative AI!
Try a free lesson

Can I overload the == operator? If yes how?

I tried in the Code Playground but it gave me an error, I tried overloading != but that gave me an error as well.

3rd Feb 2017, 4:24 PM
SIMOMEGA - avatar
4 Answers
+ 2
Yes you can: "User-defined value types can overload the == operator"
3rd Feb 2017, 6:05 PM
+ 1
You can't overload == i think but you could override the Equals(object other) method like this: public override bool Equals(object other) { // your custom equality checks here ... }
3rd Feb 2017, 5:44 PM
+ 1
Thx Alvaro I'll check that out.
4th Feb 2017, 3:47 PM
SIMOMEGA - avatar
In Java you can't, I am pretty sure you can't do it in C# either.
3rd Feb 2017, 5:00 PM
Ladislav Milunović
Ladislav Milunović - avatar