Advertisement
UrayFenn

ReadInt

Feb 24th, 2024
778
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 0.93 KB | None | 0 0
  1. namespace ReadInt
  2. {
  3.     internal class Program
  4.     {
  5.         static void Main(string[] args)
  6.         {
  7.             Console.WriteLine("Введите число для конвертации:");
  8.             int numberFromUser = GetNumber();
  9.             Console.ReadKey();
  10.         }
  11.  
  12.         static int GetNumber()
  13.         {
  14.             int number = 0;
  15.             bool isWork = true;
  16.  
  17.             while (isWork)
  18.             {
  19.                 string userInput = Console.ReadLine();
  20.  
  21.                 if (int.TryParse(userInput, out number))
  22.                 {
  23.                     Console.WriteLine("Число сконвертировано!");
  24.                     isWork = false;
  25.                 }
  26.                 else
  27.                 {
  28.                     Console.WriteLine("Некорректный ввод попробуйте снова!");
  29.                 }
  30.             }
  31.  
  32.             return number;
  33.         }
  34.     }
  35. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement