Advertisement
Vlad_Savitskiy

ReadInt

Apr 14th, 2020
130
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 0.71 KB | None | 0 0
  1. using System;
  2.  
  3. namespace CSLightFirst
  4. {
  5.     class Program
  6.     {
  7.         static void Main()
  8.         {
  9.             while (true)
  10.                 TryParseUserInput();
  11.         }
  12.  
  13.         private static void TryParseUserInput()
  14.         {
  15.             string userInput;
  16.             int resultNumber;
  17.  
  18.             Console.Write("Введите целое число: ");
  19.             userInput = Console.ReadLine();
  20.  
  21.             if (int.TryParse(userInput, out resultNumber))
  22.                 Console.WriteLine($"\nВаше число {resultNumber}\n");
  23.             else
  24.                 Console.WriteLine("Число введено некорректно, попробуйте ещё раз\n");
  25.         }
  26.     }
  27. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement