本文介绍了随机时间限制的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我有一个包含问题和答案的项目.如何随机编码?我需要有时间来回答这个问题.我怎么做?请帮助..
I have a project with a question and an answer portion. How can I code in random? I need to have a time limit to answer the question. How do I do that? Please help..
推荐答案尝试: ... Random r = new Random(); int questionNumber = r.Next(0, numberOfQuestions); AskQuestion(questionNumber); Timer t = new Timer(); t.Interval = 10000; // 10 seconds t.Elapsed+=new ElapsedEventHandler(OnTimedEvent); t.Start(); ... private static void OnTimedEvent(object source, ElapsedEventArgs e) { Timer t = source as Timer; if (t != null) { t.Stop(); } FailedToAnswerInTime(); }
有一些细节,例如将Random对象保留为类的一部分,以确保每次都不相同,确保您在一次会话中不会问相同的问题,等等.思想.
There are some details, like keeping the Random object as part of your class to ensure it is different each time, making sure you don''t ask teh same question twice in a session, etc. But those you can handle with a bit of thought.
更多推荐
随机时间限制
发布评论