-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 に答える