Pre*_*ion 6 c# validation console input
在这里谈论控制台
这个想法是,如果用户在控制台的输入提示中按下除数字之外的任何键(字母键和numpad之上的键),则不会输入任何内容.它好像控制台将忽略任何非数字键按下.
如何以正确的方式做到这一点?
尝试使用ReadKey方法:
while (processing input)
{
ConsoleKeyInfo input_info = Console.ReadKey (true); // true stops echoing
char input = input_info.KeyChar;
if (char.IsDigit (input))
{
Console.Write (input);
// and any processing you may want to do with the input
}
}
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
2602 次 |
| 最近记录: |