Advertisement
SLENSER

Untitled

May 22nd, 2019
182
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 0.74 KB | None | 0 0
  1. namespace _4_3
  2. {
  3.     class Program
  4.     {
  5.         static void Main(string[] args)
  6.         {
  7.             ReadInt();
  8.         }
  9.         static void ReadInt()
  10.         {
  11.             string str = Console.ReadLine();
  12.             int number;
  13.  
  14.             bool converted = int.TryParse(str, out number);
  15.             while (converted == false)
  16.             {
  17.                 converted = int.TryParse(str, out number);
  18.  
  19.                 if(!converted)
  20.                 {
  21.                     Console.WriteLine("Ошибка конвертации '{0}'", str);
  22.                     str = Console.ReadLine();
  23.                 }
  24.             }
  25.             Console.WriteLine("Преобразован '{0}' в {1}.", str, number);
  26.  
  27.         }
  28.     }
  29. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement