Skip to content

Instantly share code, notes, and snippets.

@StrikerXx798
Last active April 19, 2025 13:22
Show Gist options
  • Save StrikerXx798/3a829eccaf671417a13d13c74f466e42 to your computer and use it in GitHub Desktop.
Save StrikerXx798/3a829eccaf671417a13d13c74f466e42 to your computer and use it in GitHub Desktop.
ДЗ: ReadInt
using System;
namespace ConsoleApp1
{
internal class Program
{
static void Main(string[] args)
{
int number = GetNumber();
Console.WriteLine($"Вы ввели число: {number}");
}
static int GetNumber()
{
int number = int.MinValue;
bool isValid = false;
while (isValid == false)
{
Console.Write("Введите любое число: ");
string input = Console.ReadLine();
isValid = int.TryParse(input, out number);
if (!isValid)
{
Console.WriteLine("Некорректный ввод. Пожалуйста, введите число.");
}
}
return number;
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment