所以我正在为一个类似测验的应用程序编写一个简单的程序。我有一个我为其设置变量的问题类,但我错过了定义所有问题并调用其属性的有效方法。
Questions question1 = new Questions();
string choice;
public Form3()
{
InitializeComponent();
question1.ID = 1;
question1.Question = "My friend _____ 27 years old.";
question1.AnswerA = "be";
question1.AnswerB = "is";
question1.AnswerC = "are";
question1.AnswerD = "am";
question1.CorAnswer = "is";
GenQuestion();
}
private void GenQuestion()
{
questionLbl.Text = question1.Question;
aBtn.Text = question1.AnswerA;
bBtn.Text = question1.AnswerB;
cBtn.Text = question1.AnswerC;
dBtn.Text = question1.AnswerD;
}
那么有没有更有效的方法将问题1设置为其他内容?我在想像
int curQuestion = 1;
questionLbl.Text = question{curQuestion}.Question;
aBtn.Text = question{curQuestion}.AnswerA;
...
curQuestion++;
这可能吗?或者我需要单独定义每个文本吗?
答案 0 :(得分:1)
您可以将问题存储在List中,然后将ListView与对象数据源一起使用。