If you use the built in type Point (part of System.Drawing) you won't have to overload - they work as expected.
If you just want to see how to implement operator overloading, here's a sample:
Code:
struct MyStruct
{
public int x;
public int y;
public MyStruct(int x, int y)
{
this.x = x;
this.y = y;
}
public static bool operator ==(MyStruct v1, MyStruct v2)
{
return (v1.x==v2.x && v1.y==v2.y);
}
public static bool operator !=(MyStruct v1, MyStruct v2)
{
return (v1.x!=v2.x || v1.y!=v2.y);
}
}
And here's the sample code to test:
Code:
MyStruct m1 =
new MyStruct
(1,
2);
MyStruct m2 =
new MyStruct
(3,
4);
MyStruct m3 =
new MyStruct
(1,
2);
// The following is true;if(m1 == m3
) Debug.
WriteLine("=");
// The following is not trueif(m1 == m2
) Debug.
WriteLine("=");
-nerseus