随机时间限制

编程入门 行业动态 更新时间:2024-10-17 05:28:36
本文介绍了随机时间限制的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述

我有一个包含问题和答案的项目.如何随机编码?我需要有时间来回答这个问题.我怎么做?请帮助..

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.

更多推荐

随机时间限制

本文发布于:2023-11-27 07:45:33,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1637162.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:时间

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!