Delegate
Delegate
namespace CalculatorApp
{
// Delegate declaration
public delegate double MathOperation(double num1, double num2);
class Program
{
static void Main(string[] args)
{
MathOperations mathOps = new MathOperations();
switch (choice)
{
case "+":
operation = mathOps.Add;
break;
case "-":
operation = mathOps.Subtract;
break;
case "*":
operation = mathOps.Multiply;
break;
case "/":
operation = mathOps.Divide;
break;
default:
Console.WriteLine("Invalid operation.");
return;
}
try
{
double result = operation(num1, num2);
Console.WriteLine($"Result: {result}");
}
catch (DivideByZeroException ex)
{
Console.WriteLine(ex.Message);
}
}
}
}