- android - 多次调用 OnPrimaryClipChangedListener
- android - 无法更新 RecyclerView 中的 TextView 字段
- android.database.CursorIndexOutOfBoundsException : Index 0 requested, 光标大小为 0
- android - 使用 AppCompat 时,我们是否需要明确指定其 UI 组件(Spinner、EditText)颜色
我用 C# 做了一个测验,我的问题是用随机数随机问的。问题是我只想在每种情况下去一次。我怎样才能做到这一点?
感谢您的回答。
Random rdmNb = new Random();
int rdm1 = rdmNb.Next(1, 11);
switch (rdm1)
{
case 1:
lblQuesttion.Text = strQ1;
break;
case 2:
lblQuesttion.Text = strQ2;
break;
case 3:
lblQuesttion.Text = strQ3;
break;
case 4:
lblQuesttion.Text = strQ4;
break;
case 5:
lblQuesttion.Text = strQ5;
break;
case 6:
lblQuesttion.Text = strQ6;
break;
case 7:
lblQuesttion.Text = strQ7;
break;
case 8:
lblQuesttion.Text = strQ8;
break;
case 9:
lblQuesttion.Text = strQ9;
break;
case 10:
lblQuesttion.Text = strQ10;
break;
}
最佳答案
列出你的问题
List<string> questions = new List<string>()
{
strQ1,strQ2,strQ3,strQ4,strQ5,strQ6,strQ7,strQ8,strQ9,strQ10
};
然后改变你的随机生成从列表中找到一个问题
Random rdmNb = new Random();
int rdm1 = rdmNb.Next(0, questions.Count);
lblQuesttion.Text = questions[rdm1];
并从列表中删除提出的问题
questions.RemoveAt(rdm1);
无需切换....
请务必在驱动您选择下一个问题的循环外声明随机变量。如本例所示
// Declare globally the random generator, not inside the question loop
Random rdmNb = new Random();
while (questions.Count > 0)
{
int rdm1 = rdmNb.Next(0, questions.Count);
string curQuestion = questions[rdm1];
questions.RemoveAt(rdm1);
lblQuestion.Text = curQuestion;
... ?code to handle the user input?
}
编辑
在表单内声明和初始化具有全局范围的问题列表。
public class MyForm : Form
{
// Declaration at global level
List<string> questions;
public MyForm()
{
InitializeComponent();
LoadQuestions();
}
private void LoadQuestions()
{
questions = new List<string>()
{
strQ1,strQ2,strQ3,strQ4,strQ5,strQ6,strQ7,strQ8,strQ9,strQ10
};
// In future you could change this method to load your questions
// from a file or a database.....
}
}
关于c# - 我怎样才能在开关盒中只走一次?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/34565330/
我想递归地遍历一个目录,但我希望 python 在遇到包含超过 100 个文件的目录时从任何单个 listdir 中断。基本上,我正在搜索 (.TXT) 文件,但我想避免使用包含大型 DPX 图像序列
我正在尝试遍历列表(例如 sql 行)并为每一行触发例程。问题是传递给函数的值不会在运行时进行评估,因此根据函数执行所需的时间,它可能会使用下一行中的任何值而不是当前行。 我知道我可以在普通函数中提取
我需要以毫秒为单位的时间来处理大量事务,因此我想要正确且快速的东西。下面的工作会做得最好吗? : iMilli := int((time.Nanoseconds() % 1e6) / 1e3
我有以下目录/文件设置(已简化): Ce +---top.txt +---X0.0 | | | +---Y0.0 | | | | |
我遇到了类似的问题: Connecting to Redis To Go with PHP 基本上,我在 redis 中有这个 uri: redis://myusername:foopassword@
我阅读了下面的主题 Go: multiple value in single-value context 但我不明白这个解释在我的案例中。可能是因为我想使用 interface 在下面的情况下,我得到
我有一个模板,我想使用 text/template 评估各个字段包裹。我很难弄清楚评估应该如何工作,因为下面的代码似乎失败了。模板包是否足够强大以处理此类评估? type something stru
我编写了简单的服务器程序来从客户端接收数据。我有点不明白有时我从函数中得到错误 read tcp4 IP:PORT i/o timeoutint, err := conn.Read([]byte) 未
我只需要解码和更新 json 对象的特定值。问题是我不知道对象的完整结构。 encoding/json 包“忽略”/截断结构中未提供的字段,因此在编码时这些字段将丢失。 我想知道是否可以只解码我知道的
我正在尝试使用带有 C++ 目标的 ANTLR4 来实现 TSql 解析器。我抓取了语法文件 here .该jar用于制作相应的源文件(因冲突将TSqlParser.cpp中的NULL全部改为null
我在 win7 中使用 python 3.3.3 - 我只想列出网络目录中的所有文件。 import os for root, dirs, files in os.walk("X:\\network\
当我运行 go 脚本 ( go run example.go ) 时出现此错误 /home/travis/.gvm/gos/go1.1.2/src/pkg/github.com/user/exampl
我正在尝试通过 gmail API 发送电子邮件使用 Go但我发现文档非常有缺陷/令人困惑。这一次我看不到收据字段和电子邮件正文。 我不需要上传任何东西,所以我找到了 Simple upload ,
本人是一名专业的windows/.Net开发者,一直在慢慢学习rails/ruby/python/etc。在我有空的时候。在过去 8 年左右的时间里,我也一直在使用各种 Linux 发行版。然而,有一
我想知道是否可以使用 std http 来响应 http 请求打包并仍然保持 go 例程事件(例如运行任务密集型任务)。用例是我需要接收一个 http 请求,然后在几分钟后回调该服务 最佳答案 只需从
我想知道关于指针的最佳实践是什么。我应该在结构上还是在其字段上定义它们。我虽然定义一个指向结构本身的指针是有意义的,但这里有一个我觉得很有趣的例子。如果所有字段都是指针,为什么我不应该使用指向整个结构
我是一名优秀的程序员,十分优秀!