在提供有效输入之前询问值也许使用do-while循环

问题描述

我有这段代码:

string yourName;
        do { yourName = Console.ReadLine(); }
        while (!yourName.All(Char.IsLetter));

检查字母后,我要输出“请输入有效名称”。如果字符串中确实包含数字。

是否可以在do-while循环内进行? 如果没有,您能提出任何解决方案吗?

编辑:已解决。我改用while循环:

string yourName;
yourName = Console.ReadLine();
while (!yourName.All(Char.IsLetter))
        {
            Console.Write("Please Enter a Valid Name: ");
            yourName = Console.ReadLine();
        }

解决方法

暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!

如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。

小编邮箱:dio#foxmail.com (将#修改为@)

相关问答

错误1:Request method ‘DELETE‘ not supported 错误还原:...
错误1:启动docker镜像时报错:Error response from daemon:...
错误1:private field ‘xxx‘ is never assigned 按Alt...
报错如下,通过源不能下载,最后警告pip需升级版本 Requirem...