Advertisement
TeT91

ДЗ ReadInt

May 16th, 2024
681
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 0.89 KB | None | 0 0
  1. using System;
  2.  
  3. namespace CSLight
  4. {
  5.     internal class Program
  6.     {
  7.         static void Main(string[] args)
  8.         {
  9.             Console.WriteLine(TryToConvert());
  10.             Console.ReadKey();
  11.         }
  12.  
  13.         private static int TryToConvert()
  14.         {
  15.             bool isConverted = false;
  16.             int number = 0;
  17.  
  18.             while (isConverted == false)
  19.             {
  20.                 Console.WriteLine("Введите число");
  21.                 string uerInput = Console.ReadLine();
  22.                 if (int.TryParse(uerInput, out number))
  23.                 {
  24.                     isConverted = true;
  25.                 }
  26.                 else
  27.                 {
  28.                     Console.WriteLine("Не удалось конвертировать, попробуйте еще раз.");
  29.                 }
  30.             }
  31.  
  32.             return number;
  33.         }
  34.     }
  35. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement