46 lines
1.3 KiB
C#
46 lines
1.3 KiB
C#
using System;
|
|
|
|
namespace su.divan2000.UtilsTUI
|
|
{
|
|
public static class InputHelper
|
|
{
|
|
public static double AskDouble(string prompt)
|
|
{
|
|
double val;
|
|
while (true)
|
|
{
|
|
Console.Write(prompt);
|
|
if (double.TryParse(Console.ReadLine(), out val))
|
|
return val;
|
|
|
|
Console.WriteLine("Некорректный ввод. Введите число в формате 1.0, 2.5 и т.д.");
|
|
}
|
|
}
|
|
|
|
public static int AskInt(string prompt)
|
|
{
|
|
int val;
|
|
while (true)
|
|
{
|
|
Console.Write(prompt);
|
|
if (int.TryParse(Console.ReadLine(), out val))
|
|
return val;
|
|
|
|
Console.WriteLine("Некорректный ввод. Введите целое число.");
|
|
}
|
|
}
|
|
|
|
public static bool AskYesNo(string prompt)
|
|
{
|
|
while (true)
|
|
{
|
|
Console.Write(prompt);
|
|
string? s = Console.ReadLine()?.Trim().ToLower();
|
|
if (s == "да") return true;
|
|
if (s == "нет") return false;
|
|
Console.WriteLine("Введите 'да' или 'нет'.");
|
|
}
|
|
}
|
|
}
|
|
}
|