Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System;
- using System.Collections.Generic;
- namespace DelegateCalc
- {
- internal class Program
- {
- private delegate double operation(string A, string B);
- private static Dictionary<char, operation> Operations = new Dictionary<char, operation>()
- {
- ['+'] = Plus,
- ['-'] = Minus,
- };
- private static double Plus(string A, string B)
- {
- try
- {
- double.TryParse(A, out double num1);
- double.TryParse(B, out double num2);
- return num1 + num2;
- }
- catch (Exception)
- {
- throw new ArithmeticException();
- }
- }
- private static double Minus(string A, string B)
- {
- try
- {
- double.TryParse(A, out double num1);
- double.TryParse(B, out double num2);
- return num1 - num2;
- }
- catch (Exception)
- {
- throw new ArithmeticException();
- }
- }
- private static void Main(string[] args)
- {
- Console.WriteLine("Введите выражение");
- var separators = new List<char>();
- foreach (var item in Operations.Keys)
- {
- separators.Add(item);
- }
- var exp = Console.ReadLine().Split(separators.ToArray());
- }
- private static double Resolve(string[] exp)
- {
- return Operations[exp[1].ToCharArray()[0]](exp[0], exp[2]);
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement