需要有关如何创建用户可以重新输入数据的程序的信息. [英] need info about how i can create program that user can re-enter data.

查看:56
本文介绍了需要有关如何创建用户可以重新输入数据的程序的信息.的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我需要有关如何允许用户重新输入已检测为无效的数据(不退出程序)的帮助.

例如,如何使它重新输入而不退出. :

I need help on how I can allow the user to re-enter data that has been detected as invalid (not exit the program).

for example how can I make this to be re-entered and not exit. :

 Console.Write("Enter Street Number >");
                    vtemp = Console.ReadLine();
                    street_number = vtemp;
                    if (string.IsNullOrEmpty(street_number))
                    {
                        Console.WriteLine("Please enter correct data");
                        return; 
}




感谢




Thanks

推荐答案

当然,您可以在循环中请求相同的数据,直到用户满足输入数据约束为止.那应该可以回答您的问题.

但是,这对用户来说非常丑陋和令人讨厌.大多数有文化的控制台应用程序都设计为无需任何交互式输入即可使用.而是在命令行中一次输入所有参数.如果它们太多,则一个或多个参数可能会指定某种输入文件,您在其中放置了大多数输入参数. (不过,这种不互动的经验法则有一些臭名昭著的排除方法.)

如果您采用这种方式,可以使用我强大的易于使用的命令行解析实用程序:
基于枚举的命令行实用程序 [
Of course you can request the same data in the loop until the user meets the input data constraints. That should answer your question.

However, it''s pretty ugly and annoying to the users. Most cultured console applications are designed to be used without any interactive input. Instead, all the parameters are entered at once in a command line. If there are too many of them, one or more of the parameters could specify some kind of input file(s) where you put most of input parameters. (There are some notorious exclusions from this no-interactive rule of thumb though.)

If you what to go in this way, you can use my robust easy-to-use command line parsing utility:
Enumeration-based Command Line Utility[^].

You can use another more comprehensive (but perhaps less easy to use for a developer) library I referenced in my article.

Alternatively, you can think to provide more convenient user input through windowed UI, either with System.Windows.Forms or WPF library.

—SA




您可以使用do ... while循环执行相同的操作.您需要从while循环中获取正确的日期,直到可以要求用户一次又一次地输入正确的数据为止.

但是我更喜欢您添加一些限制,例如输入10或20次以输入无效数据,然后应用程序应该退出并显示相应的消息.

谢谢
-Amit Gajjar
Hi,

You can use do... while loop to do the same. you need to come out from the while loop when you are getting correct date, till you can ask user to enter correct data again and again.

But i prefer you to add some limit say 10 or 20 times to enter invalid data then application should be exit with appropriate message.

Thanks
-Amit Gajjar


这篇关于需要有关如何创建用户可以重新输入数据的程序的信息.的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆