static void FunctionExecutionExample() { ScienceSubject ss = new ScienceSubject(); //ss.Test(10); var a = new Arithmetic(); var b = new Arithmetic(25); }
static void OperatorOverloadingExample() { int a = 20; int b = 30; var res = a + b; var aObj = new Arithmetic() { i = 35, str = "Some " }; var bobj = new Arithmetic() { i = 45, str = "String" }; var resObj = aObj + bobj; var resObj1 = aObj + bobj; var resObj2 = aObj + bobj; var resObj3 = aObj + bobj; var resObj4 = aObj + bobj; Console.WriteLine("Final i => " + resObj.i); Console.WriteLine("Final str => " + resObj.str); aObj++; Console.WriteLine("Final i => " + aObj.i); Console.WriteLine("Final str => " + aObj.str); aObj = new Arithmetic() { i = 35, str = "Some " }; bobj = new Arithmetic() { i = 35, str = "Some " }; var cObj = new Arithmetic() { i = aObj.i + bobj.i, str = aObj.str + bobj.str, Price = aObj.Price + bobj.Price }; var dObj = new Arithmetic() { i = aObj.i + bobj.i, str = aObj.str + bobj.str, Price = aObj.Price + bobj.Price }; var eObj = new Arithmetic() { i = aObj.i + bobj.i, str = aObj.str + bobj.str, Price = aObj.Price + bobj.Price }; var result = (aObj == bobj); Console.WriteLine("result => " + result); //&& || }
public static Arithmetic operator +(Arithmetic a, Arithmetic b) { var finalresult = a.i + b.i; var finalString = a.str + b.str; var finalPrice = a.Price + b.Price; var res = new Arithmetic() { i = finalresult, str = finalString, Price = finalPrice }; return(res); }