Advertisement
OldBeliver

Function_03ver03

Mar 27th, 2021
73
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 1.01 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 ReadInt_03
  8. {
  9.     class Program
  10.     {
  11.         static void Main(string[] args)
  12.         {
  13.             ReadInt();
  14.  
  15.             Console.ReadKey();
  16.         }
  17.  
  18.         static int ReadInt()
  19.         {            
  20.             bool result;
  21.             int number;
  22.  
  23.             while (true)
  24.             {
  25.                 Console.Write($"Введите целое число: ");                
  26.  
  27.                 result = int.TryParse(Console.ReadLine(), out number);
  28.  
  29.                 if(result == true)
  30.                 {
  31.                     Console.WriteLine($"Вы ввели число {number}");
  32.                     return number;                    
  33.                 }
  34.                 else
  35.                 {
  36.                     Console.Clear();
  37.                     Console.WriteLine($"что-то пошл не так");
  38.                 }
  39.             }
  40.         }
  41.     }
  42. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement