You also want an ePaper? Increase the reach of your titles
YUMPU automatically turns print PDFs into web optimized ePapers that Google loves.
Operator Overloading<br />
using System;<br />
class Client{<br />
static void Main(string[] args){<br />
Point p1 = new Point();<br />
p1.x = 10; p1.y=10;<br />
Point p2 = new Point();<br />
p2.x = 10; p2.y=10;<br />
Point p3 = p1 + p2;<br />
Console.WriteLine("p3.x:{0} p3.y:{1}",p3.x,p3.y);<br />
}<br />
}<br />
class Point{<br />
public int x;<br />
public int y;<br />
public static Point operator+(Point p1, Point p2){<br />
Point p = new Point();<br />
p.x = p1.x + p2.x;<br />
p.y = p1.y + p2.y;<br />
return p;<br />
}<br />
}<br />
Use the operator keyword<br />
and whichever operator<br />
you wish to overload<br />
45