Advertisement
IGRODELOFF

HW: FunctionReadline

Dec 10th, 2024
62
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 0.97 KB | None | 0 0
  1. using System;
  2.  
  3. namespace homeWorkFunctionReadline
  4. {
  5.     internal class Program
  6.     {
  7.         static void Main(string[] args)
  8.         {
  9.             int nubmer = GetNumber();
  10.             Console.WriteLine($"Вы ввели число: {nubmer}");
  11.         }
  12.  
  13.         static int GetNumber()
  14.         {
  15.             int result = 0;
  16.  
  17.             string userInput;
  18.  
  19.             bool isExit = false;
  20.  
  21.             while (isExit == false)
  22.             {
  23.                 Console.Clear();
  24.                 Console.Write("Введите целое число: ");
  25.  
  26.                 userInput = Console.ReadLine();
  27.  
  28.                 if (int.TryParse(userInput, out result))
  29.                 {
  30.                     isExit = true;
  31.                 }
  32.                 else
  33.                 {
  34.                     Console.WriteLine("\nПожалуйства ведите корректное число.");
  35.                 }
  36.             }
  37.  
  38.             return result;
  39.         }
  40.     }
  41. }
  42.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement