//Program to Oveload + Operator
using System;
class Location
{
public int X,Y;
// Operator overloading
public static Location operator +(Location a1,Location a2)
{
Location a3=new Location();
a3.X=a1.X+a2.X;
a3.Y=a1.Y+a2.Y;
return a3;
}
}
class Program
{
static void Main()
{
Location L1=new Location();
L1.X=200;
L1.Y=300;
Location L2=new Location();
L2.X=100;
L2.Y=500;
Location L3;
L3=L1+L2;
Console.WriteLine("L1 Data X={0}, Y={1}",L1.X,L1.Y);
Console.WriteLine("L2 Data X={0}, Y={1}",L2.X,L2.Y);
Console.WriteLine("L3 Data X={0}, Y={1}",L3.X,L3.Y);
}
}
No comments:
Post a Comment