Advertisement
LeRoY_Go

Untitled

Feb 2nd, 2022
687
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 0.88 KB | None | 0 0
  1. using System;
  2.  
  3. namespace C_Sharp_Junior
  4. {
  5.     class Program
  6.     {
  7.         static void Main(string[] args)
  8.         {
  9.             Console.Write("Преобразование завершилось удачно: " + ReadInt());
  10.             Console.ReadKey();
  11.         }
  12.         static int ReadInt()
  13.         {
  14.             while (true)
  15.             {
  16.                 Console.Write("Введите строку:");
  17.                 string userInput = Console.ReadLine();
  18.                 bool result = int.TryParse(userInput, out int number);
  19.                 if (result == true)
  20.                 {
  21.                     return number;
  22.                 }
  23.                 else
  24.                 {
  25.                     Console.WriteLine("Преобразование завершилось неудачно. Попробуйте сново.");
  26.                 }
  27.             }
  28.         }
  29.     }
  30. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement