0

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
SIMOMEGA - avatar
4 ответов
+ 2
Yes you can: https://msdn.microsoft.com/es-es/library/53k8ybth(v=vs.71).aspx "User-defined value types can overload the == operator"
3rd Feb 2017, 6:05 PM
Álvaro
+ 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
qobus
+ 1
Thx Alvaro I'll check that out.
4th Feb 2017, 3:47 PM
SIMOMEGA
SIMOMEGA - avatar
0
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