Advertisement
Guest User

Untitled

a guest
Jan 18th, 2020
79
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.63 KB | None | 0 0
  1. using System;
  2. using System.Collections.Generic;
  3.  
  4. namespace DelegateCalc
  5. {
  6. internal class Program
  7. {
  8. private delegate double operation(string A, string B);
  9.  
  10. private static Dictionary<char, operation> Operations = new Dictionary<char, operation>()
  11. {
  12. ['+'] = Plus,
  13. ['-'] = Minus,
  14. };
  15.  
  16. private static double Plus(string A, string B)
  17. {
  18. try
  19. {
  20. double.TryParse(A, out double num1);
  21. double.TryParse(B, out double num2);
  22. return num1 + num2;
  23. }
  24. catch (Exception)
  25. {
  26. throw new ArithmeticException();
  27. }
  28. }
  29.  
  30. private static double Minus(string A, string B)
  31. {
  32. try
  33. {
  34. double.TryParse(A, out double num1);
  35. double.TryParse(B, out double num2);
  36. return num1 - num2;
  37. }
  38. catch (Exception)
  39. {
  40. throw new ArithmeticException();
  41. }
  42. }
  43.  
  44. private static void Main(string[] args)
  45. {
  46. Console.WriteLine("Введите выражение");
  47. var separators = new List<char>();
  48.  
  49. foreach (var item in Operations.Keys)
  50. {
  51. separators.Add(item);
  52. }
  53.  
  54. var exp = Console.ReadLine().Split(separators.ToArray());
  55. }
  56.  
  57. private static double Resolve(string[] exp)
  58. {
  59. return Operations[exp[1].ToCharArray()[0]](exp[0], exp[2]);
  60. }
  61.  
  62. }
  63. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement