- using System;
- public struct addOpp {
- private double a;
- public addOpp(double a) {
- this.a = a;
- }
- public override string ToString() {
- return a.ToString();
- }
- static public addOpp operator + (addOpp lhs, addOpp rhs) {
- return new addOpp(lhs.a + rhs.a);
- }
- }
- class Operoverload {
- static void Main(string[] args) {
- Console.WriteLine("Enter Two Numbers");
- addOpp c1 = new addOpp(Convert.ToInt16(Console.ReadLine()));
- addOpp c2 = new addOpp(double.Parse(Console.ReadLine()));
- addOpp c3 = c1 + c2;
- Console.WriteLine("First Value is " + c1);
- Console.WriteLine("Second Value is " + c2);
- Console.WriteLine("Addition is " + c3);
- Console.ReadKey();
- }
- }
This code is to understand the operator overloading operation in C#.Also learn the concept of structure(struct) in c#.
