static void Main(string[] args) { GetGreeting del = GoodMorning; UseOperation delegat = Add; if (DateTime.Now.Hour < 12) { del = GoodMorning; } else if (DateTime.Now.Hour >= 12 && DateTime.Now.Hour < 18) { del = GoodDay; } else if (DateTime.Now.Hour >= 18 && DateTime.Now.Hour < 22) { del = GoodEvening; } else if (DateTime.Now.Hour >= 22 || DateTime.Now.Hour < 11) { del = GoodEvening; } del(); Console.WriteLine(" Введите числа для расчёта"); Console.Write(" a - "); int a = Convert.ToInt32(Console.ReadLine()); Console.Write(" b - "); int b = Convert.ToInt32(Console.ReadLine()); Console.Write(" Какую операцию провернуть (+,-,*,/) - "); string operacia = Convert.ToString(Console.ReadLine()); if (operacia == "+") { delegat = Add; } else if (operacia == "-") { delegat = Subtract; } else if (operacia == "*") { delegat = Multiply; } else if (operacia == "/") { delegat = IntegerDevide; } delegat(a, b); }
private static void Task5() { //Task 5 Console.WriteLine("Enter command code"); Console.WriteLine("1.Sum"); Console.WriteLine("2.Minus"); Console.WriteLine("3.Mult"); Console.WriteLine("4.Div"); Console.WriteLine("Enter X"); var userX = int.Parse(Console.ReadLine()); Console.WriteLine("Enter Y"); var userY = int.Parse(Console.ReadLine()); var input = Console.ReadLine(); var code = int.Parse(input); UseOperation useOperation = (x, y) => { switch (code) { case 0: return(Sum(x, y)); case 1: return(Minus(x, y)); case 2: return(Mult(x, y)); case 3: return(Div(x, y)); } throw new NotSupportedException(); }; useOperation.Invoke(userX, userY); }