Smart    Lucky

Smart Lucky

  • NA
  • 555
  • 641k

Operator Overloading

Jul 5 2011 9:53 AM

Hi Dudes

Can any one tell me

and what is the real use of operator overloading and below i have make a program can any one explain it.....?

 

 

using System;
class Training
{
string course;
int duration;

public Training(string course, int duration)
{
this.course = course;
this.duration = duration;
}
public static int operator +(Training t1, Training t2)
{
return t1.duration - t2.duration;
}
}

 

class Program
{
public static void Main()
{
Training t1 = new Training("PHP", 4);
Training t2 = new Training("ASP.NET", 4);
int total = t1 + t2;
Console.WriteLine(total);
Console.ReadKey();
}
}

Answers (1)