32 lines
867 B
C#
32 lines
867 B
C#
|
using System;
|
|||
|
using System.Collections.Generic;
|
|||
|
using System.Linq;
|
|||
|
using System.Text;
|
|||
|
using System.Threading.Tasks;
|
|||
|
|
|||
|
namespace ConsoleApp2.Helpers
|
|||
|
{
|
|||
|
public static class ValidateConsole
|
|||
|
{
|
|||
|
public static void ValidateInput<T>(Func<string,bool> converter,string message)
|
|||
|
{
|
|||
|
Console.Write(message);
|
|||
|
string ? input = Console.ReadLine();
|
|||
|
while (true)
|
|||
|
{
|
|||
|
if (!string.IsNullOrEmpty(input))
|
|||
|
{
|
|||
|
var result = converter(input);
|
|||
|
if (result == false)
|
|||
|
{
|
|||
|
Console.WriteLine($"输入的内容不合法,请重新输入!");
|
|||
|
input = Console.ReadLine();
|
|||
|
}
|
|||
|
else break;
|
|||
|
}
|
|||
|
break;
|
|||
|
}
|
|||
|
}
|
|||
|
}
|
|||
|
}
|