class Point
{
private int m_PointX;
private int m_PointY;
public Point(int x, int y)
{
m_PointX = x;
m_PointY = y;
}
public static Point operator+(Point point1, Point point2)
{
Point P = new Point();
P.X = point1.X + point2.X;
P.Y = point1.Y + point2.Y;
return P;
}
}
Example:
Point P1 = new Point(10,20);
Point P2 = new Point(30,40)
P1+P2; // operator overloading
Here is an example for #2
public static Point operator+(int value, Point point2)
{
// logic here.
}
You will have to do the other way with the parameters if you want P2 + 2
to work.
See http://msdn.microsoft.com/en-us/library/8edha89s.aspx for more information.
To answer your questions:
null
s as well.int
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With