private static void callStaticMethods() { Console.WriteLine("The Added value is " + MathComponent.AddFunc(123, 23)); Console.WriteLine("The Subtracted value is " + MathComponent.SubFunc(123, 23)); Console.WriteLine("The Multiplied value is " + MathComponent.MulFunc(123, 23)); Console.WriteLine("The Divided value is {0:#.##}", MathComponent.DivFunc(12876873, 23)); }
private static void paramsExample() { //Params allows to pass variable no of args to the function. It is similar to ... of C++. //Params should be last of the paramter list, It will always be an array, there can be only one params within a function. Params cannot be passed using ref or out keywords. double res = MathComponent.GetSum(123, 23, 34, 23, 234, 234, 4, 5, 5, 23, 4); Console.WriteLine("The Final Sum:" + res); }
static void Main(string[] args) { MathComponent com = new MathComponent(); Console.WriteLine(com.AddFunc(123, 324)); Console.WriteLine(com.SubFunc(123, 324)); Console.WriteLine(com.MulFunc(123, 324)); Console.WriteLine(com.DivFunc(123, 324)); }
private static void passByReferenceExample() { //The values that is passed to the function as reference is initialized before sending into the function. //With out parameter, the caller need not intialize the values, rather he gets the values from the function similar to an output of a function, hense the name out parameter.. double added = 0, subtracted = 0, multiplied = 0, div = 0; MathComponent.AllFunctions(14, 2, ref added, ref subtracted, ref multiplied, out div); Console.WriteLine("The Multiplied value " + multiplied); Console.WriteLine("The Divided value " + div); }