Advertisement
nikitaTheSlayer

Lesson: ReadInt

Apr 17th, 2020
266
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 0.92 KB | None | 0 0
  1. using System;
  2.  
  3. namespace CSLight_4._2
  4. {
  5.     class Program
  6.     {
  7.         static void Main(string[] args)
  8.         {
  9.             Console.WriteLine(ReadInt());
  10.         }
  11.  
  12.         static int ReadInt()
  13.         {
  14.             string input;
  15.             bool result;
  16.             int number = 0;
  17.  
  18.             Console.Write("Введите целое число: ");
  19.             while(true)
  20.             {
  21.                 input = Console.ReadLine();
  22.                 result = int.TryParse(input, out number);
  23.  
  24.                 if (result)
  25.                 {
  26.                     Console.Write("Число сконвертировано: ");
  27.                     break;
  28.                 }
  29.                 else
  30.                 {
  31.                     Console.WriteLine("Введенное число неверно! Повторите попытку");
  32.                 }
  33.             }
  34.             return number;
  35.         }
  36.     }
  37. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement