修改
This commit is contained in:
31
ConsoleApp2/Helpers/ValidateConsole.cs
Normal file
31
ConsoleApp2/Helpers/ValidateConsole.cs
Normal file
@@ -0,0 +1,31 @@
|
||||
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;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user