Anonim_999

Untitled

Feb 22nd, 2021 (edited)
1,318
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 0.89 KB | None | 0 0
  1. using System;
  2.  
  3. namespace ConsoleApp1
  4. {
  5.     class Program
  6.     {
  7.         static void Main(string[] args)
  8.         {
  9.             int numberUser = CountNumber();
  10.             Console.WriteLine($"Возвращенное число: {numberUser}");
  11.         }
  12.  
  13.         private static int CountNumber()
  14.         {
  15.             int number;
  16.            
  17.             while (true)
  18.             {
  19.                 Console.Write("Введите число: ");
  20.                 string userInput = Console.ReadLine();
  21.                 bool success = Int32.TryParse(userInput, out number);
  22.  
  23.                 if (success)
  24.                 {
  25.                     return number;
  26.                 }
  27.                 else
  28.                 {
  29.                     Console.WriteLine($"Попытка преобразования '{userInput}' неудачна.");
  30.                 }
  31.  
  32.             }
  33.         }
  34.     }
  35. }
Add Comment
Please, Sign In to add comment