Advertisement
LeRoY_Go

Untitled

Feb 2nd, 2022
812
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 1.00 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.             int numberConverted = 0;
  15.             bool result = false;
  16.             while (!result)
  17.             {
  18.                 Console.Write("Введите строку:");
  19.                 string userInput = Console.ReadLine();
  20.                 result = int.TryParse(userInput, out int number);
  21.                 if (result == true)
  22.                 {
  23.                     numberConverted = number;
  24.                 }
  25.                 else
  26.                 {
  27.                     Console.WriteLine("Преобразование завершилось неудачно. Попробуйте сново.");
  28.                 }
  29.             }
  30.             return numberConverted;
  31.         }
  32.     }
  33. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement