Operator Overloading In C#

  1. using System;  
  2. public struct addOpp {  
  3.     private double a;  
  4.     public addOpp(double a) {  
  5.         this.a = a;  
  6.     }  
  7.     public override string ToString() {  
  8.         return a.ToString();  
  9.     }  
  10.     static public addOpp operator + (addOpp lhs, addOpp rhs) {  
  11.         return new addOpp(lhs.a + rhs.a);  
  12.     }  
  13. }  
  14. class Operoverload {  
  15.     static void Main(string[] args) {  
  16.         Console.WriteLine("Enter Two Numbers");  
  17.         addOpp c1 = new addOpp(Convert.ToInt16(Console.ReadLine()));  
  18.         addOpp c2 = new addOpp(double.Parse(Console.ReadLine()));  
  19.         addOpp c3 = c1 + c2;  
  20.         Console.WriteLine("First Value is " + c1);  
  21.         Console.WriteLine("Second Value is " + c2);  
  22.         Console.WriteLine("Addition is " + c3);  
  23.         Console.ReadKey();  
  24.     }  
  25. }