public class ParamArithmeticOperation
{
static void Main()
{
//calling function
PerformArithmeticOperation(200,100,"+"); //perform addition
PerformArithmeticOperation(200,100,"-"); //perform subtraction
PerformArithmeticOperation(200,100,"*"); //perform multiplication
PerformArithmeticOperation(200,100,"/"); //perform division
}
//called function
public static void PerformArithmeticOperation(params object[] items)
{
var result = 0;
switch (Convert.ToString(items[2])) //items[2] is the operator(s) i.e. +,-,*,/
{
case '+': result = Convert.ToInt32(items[0]) + Convert.ToInt32(items[1]); break;
case '-': result = Convert.ToInt32(items[0]) - Convert.ToInt32(items[1]); break;
case '*': result = Convert.ToInt32(items[0]) * Convert.ToInt32(items[1]); break;
case '/': result = Convert.ToInt32(items[0]) / Convert.ToInt32(items[1]); break;
default: Console.WriteLine("No such operation available");
}
Console.WriteLine(result);
}
}