public class BasicMathsCalculator
{
public int BasicArithmeticOperation(int a , int b, string @operator)
{
return @operator == "/" ? (a / b) :
@operator == "*" ? (a * b) :
@operator == "-" ? (a - b) :
(a + b);
}
}
Here we are using ternary operator within return statement. If @operator = "/" then perform division, if @operator = "*" perform multiplication, if @operator = "-" perform
subtraction else if nothing is specified, perform addition.