我正在开展一个项目,我在Textboxes中显示问题。在每个下面都有4个复选框,用户必须选择一个回答问题的复选框。
有什么方法可以把我的所有问题,答案等放在.txt文件中并从那里加载它们?
我不想为每个问题写一个case
(我大约有120个问题)。
到目前为止我的方式:
case 5: // Multiple Answers
txtQuestion.Text = "What are the characteristics of the " +
"Main method? (Choose two)";
grpSingleChoice.Visible = false;
grpMultipleChoice.Visible = true;
chkAnswer1.Text = "A. It must always return void";
chkAnswer2.Text = "B. It is always the first method inside the " +
"main class of a program";
chkAnswer3.Text = "C. It is the start and end point of a program";
chkAnswer4.Text = "D. It must always be passed an array of strings " +
"as in static void Main(string[] args)";
chkAnswer5.Visible = true;
chkAnswer5.Text = "E. It must be created inside of a class" +
"or a structure";
break;
答案 0 :(得分:1)
这样做的一个简单方法是:
[START]
Question = Imagine you write code and include a backslash in a string, the compiler ...
Correct = 2
Option = Answer a
Option = Answer b
Option = Answer c
Option = Answer d
[END]
“标签”将是您的循环条件,因此只需使用Split(lineText, " = ")
来获取值。
但XML是更好的解决方案:
<xml>
<question correct="2">
<description>Imagine you write code and include a backslash in a string, the compiler ....</description>
<option>answer</option>
<option>answer</option>
<option>answer</option>
<option>answer</option>
</question>
<question correct="3">
<description>Another question....</description>
<option>answer</option>
<option>answer</option>
<option>answer</option>
<option>answer</option>
</question>
</xml>