If we changed this statement to: DoMathProblem( Func<int, double, char> ) What t
ID: 3879886 • Letter: I
Question
If we changed this statement to:
DoMathProblem( Func<int, double, char> )
What type of argument would be expected for the mathMethod parameter; what would be the expected arguments and return type?
-----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace Assignment1c
{
class Program
{
static void Main(string[] args)
{
Console.Write("Enter first operand: ");
double num1 = double.Parse(Console.ReadLine());
Console.Write("Enter second operand: ");
double num2 = double.Parse(Console.ReadLine());
GenericMath genMath = new GenericMath() { Operand1 = num1, Operand2 = num2 };
double sum = genMath.DoMathProblem((o1, o2) => o1 + o2);
Console.WriteLine($"The sum is {sum}");
double diff = genMath.DoMathProblem((o1, o2) => o1 - o2);
Console.WriteLine($"The difference is {diff}");
double mult = genMath.DoMathProblem((o1, o2) => o1 * o2);
Console.WriteLine($"The product is {mult}");
double div = genMath.DoMathProblem((o1, o2) =>
{
if (o2 != 0)
return o1 / o2;
else
{
throw new DivideByZeroException();
}
});
Console.WriteLine($"The quotient is {div}");
#if DEBUG
Console.WriteLine("Press enter to close...");
Console.ReadLine();
#endif
}
/*static double Add(double operand1, double operand2)
{
return operand1 + operand2;
}*/
/*static double Subtract(double operand1, double operand2)
{
return operand1 - operand2;
}*/
}
}
Explanation / Answer
The argument would be a tuple containing an integer a double and an operator and the return type should be double.