How to cancel the closing of the console after the actions I performed. I make a primitive calculator.

using System; class Calculator { public static void Main() { int x; //Переменная, которая задается пользователем для выбора операции. string str; //Строка, в которую будет вводиться нужная операция float result; Console.WriteLine("Введите номер операции \n 1) Сложение \n 2) Вычитание \n 3) Умножение \n 4 Деление \n Ожидание ввода:"); str = Console.ReadLine(); x = Convert.ToInt32(str); if (x == 1) { string srt1; string srt2; float x1; float x2; Console.WriteLine("Введите первое число:"); srt1 = Console.ReadLine(); x1 = Convert.ToInt32(srt1); Console.WriteLine("Введите второе число:"); srt2 = Console.ReadLine(); x2 = Convert.ToInt32(srt2); Console.WriteLine("Сумма равна:"); result = x1 + x2; Console.WriteLine(result); } else { if (x == 2) { string srt1; string srt2; float x1; float x2; Console.WriteLine("Введите первое число:"); srt1 = Console.ReadLine(); x1 = Convert.ToInt32(srt1); Console.WriteLine("Введите второе число:"); srt2 = Console.ReadLine(); x2 = Convert.ToInt32(srt2); Console.WriteLine("Произведение равно:"); result = x1 * x2; Console.WriteLine(result); } else { Console.WriteLine("Ошибка"); } } } } 
  • one
    Add Console.ReadKey(); before the closing "}" function Main . - Igor
  • Thank. I correctly understand that after performing my operation, when you press the (any) key, the console closes. And how to make it close, for example, when entering a certain number? - kall_lightman 9:39 pm
  • You already know about Console.ReadLine(); - Igor
  • I do not understand what you're talking about. Can be more? - kall_lightman
  • while (Console.ReadLine() != "exit") { } - Igor

1 answer 1

 using System; class Calculator { public static void Main() { while(Console.ReadLine() != "exit") { //your code } } } 

A calculator will spin around until you write exit.