Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System;
- namespace ConsoleApp1
- {
- public class Calculator
- {
- public string Calculate()
- {
- return "This is an example of overloading.";
- }
- /// <summary>
- /// A simple calculation unit.
- /// </summary>
- /// <param name="number1">Numeric value one to do the evaluation by.</param>
- /// <param name="number2">Numeric value two to do the evaluation by.</param>
- /// <param name="expression">The expression to do on the two numeric values.</param>
- /// <returns>The result of the calculation.</returns>
- public string Calculate(int number1, int number2, string expression)
- {
- string ReturnValue;
- switch (expression)
- {
- case "*":
- ReturnValue = (number1 * number2).ToString();
- break;
- case "+":
- ReturnValue = (number1 + number2).ToString();
- break;
- case "-":
- ReturnValue = (number1 - number2).ToString();
- break;
- default:
- ReturnValue = "This is a unsupported action.";
- break;
- }
- return $"The result of {number1} {expression} {number2} = {ReturnValue}";
- }
- }
- class Program
- {
- static void Main(string[] args)
- {
- Calculator Calculation = new Calculator();
- Console.WriteLine(Calculation.Calculate());
- Console.WriteLine(Calculation.Calculate(25, 25, "*"));
- Console.ReadLine();
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement