holllowknight

ДЗ: ReadInt

Mar 16th, 2020
114
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 0.81 KB | None | 0 0
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Linq;
  4. using System.Text;
  5. using System.Threading.Tasks;
  6.  
  7. namespace inputNum
  8. {
  9.     class Program
  10.     {
  11.         static void Main(string[] args)
  12.         {
  13.             getMnumber();
  14.         }
  15.  
  16.         static int getMnumber()
  17.         {
  18.             string userInput;
  19.             int num;
  20.             bool inputIsNum = false;
  21.  
  22.             while (true)
  23.             {
  24.                 Console.WriteLine("Введите цело число: ");
  25.                 userInput = Console.ReadLine();
  26.                 inputIsNum = int.TryParse(userInput, out num);
  27.                 if (inputIsNum == true) break;
  28.                 Console.WriteLine("Не удалось распознать число.");
  29.             };
  30.             return num;
  31.         }
  32.     }
  33. }
Add Comment
Please, Sign In to add comment