Advertisement
Guest User

Untitled

a guest
Feb 20th, 2019
80
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.71 KB | None | 0 0
  1. using System;
  2.  
  3. namespace ConsoleApp1
  4. {
  5. public class Calculator
  6. {
  7. public string Calculate()
  8. {
  9. return "This is an example of overloading.";
  10. }
  11.  
  12. /// <summary>
  13. /// A simple calculation unit.
  14. /// </summary>
  15. /// <param name="number1">Numeric value one to do the evaluation by.</param>
  16. /// <param name="number2">Numeric value two to do the evaluation by.</param>
  17. /// <param name="expression">The expression to do on the two numeric values.</param>
  18. /// <returns>The result of the calculation.</returns>
  19. public string Calculate(int number1, int number2, string expression)
  20. {
  21. string ReturnValue;
  22.  
  23. switch (expression)
  24. {
  25. case "*":
  26. ReturnValue = (number1 * number2).ToString();
  27. break;
  28.  
  29. case "+":
  30. ReturnValue = (number1 + number2).ToString();
  31. break;
  32.  
  33. case "-":
  34. ReturnValue = (number1 - number2).ToString();
  35. break;
  36.  
  37. default:
  38. ReturnValue = "This is a unsupported action.";
  39. break;
  40. }
  41.  
  42. return $"The result of {number1} {expression} {number2} = {ReturnValue}";
  43. }
  44. }
  45.  
  46. class Program
  47. {
  48. static void Main(string[] args)
  49. {
  50. Calculator Calculation = new Calculator();
  51.  
  52. Console.WriteLine(Calculation.Calculate());
  53. Console.WriteLine(Calculation.Calculate(25, 25, "*"));
  54. Console.ReadLine();
  55. }
  56. }
  57. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement