-1

我正在做一个在文本框中显示问题的项目。在每一个下面有 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;
4

1 回答 1

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>
于 2014-05-09T16:16:22.060 回答