Advertisement
AziLif

Парсинг

Dec 10th, 2024 (edited)
46
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 0.87 KB | None | 0 0
  1. using System;
  2.  
  3. namespace ConsoleApp
  4. {
  5.     class Program
  6.     {
  7.         static void Main(string[] args)
  8.         {
  9.             ReadInt();
  10.         }
  11.  
  12.         static void ReadInt()
  13.         {
  14.             bool isWork = true;
  15.  
  16.             int number = 0;
  17.  
  18.             Console.WriteLine($"Введите любое число.");
  19.  
  20.             while (isWork)
  21.             {
  22.                 string userInput = Console.ReadLine();
  23.                 bool isConversionSuccessful = int.TryParse(userInput, out number);
  24.  
  25.                 if (isConversionSuccessful)
  26.                 {
  27.                     Console.WriteLine($"Все случилось, '{userInput}' это число {number}");
  28.                 }
  29.                 else
  30.                 {
  31.                     Console.WriteLine("Введите еще раз:");
  32.                 }
  33.             }
  34.         }
  35.     }
  36. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement