Advertisement
alexey3017

Untitled

Mar 23rd, 2020
116
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. using System.Collections.Generic;
  3. using System.Linq;
  4. using System.Text;
  5. using System.Threading.Tasks;
  6. namespace Learn1
  7. {
  8.     class Program
  9.     {
  10.         static void Main(string[] args)
  11.         {
  12.             int num = Number();
  13.             Console.WriteLine($"Вы ввели - {num}");
  14.         }
  15.         static int Number()
  16.         {
  17.             bool isActive = true;
  18.             string userInput;
  19.             int number;
  20.             while (isActive)
  21.             {
  22.                 Console.WriteLine("Введите число:");
  23.                 userInput = Console.ReadLine();
  24.                 if (int.TryParse(userInput, out number))
  25.                 {
  26.                     return number;
  27.                 }
  28.                 else
  29.                 {
  30.                     Console.WriteLine("Вы ввели не число:");
  31.                 }
  32.             }
  33.             return 0;
  34.         }
  35.     }
  36. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement