質問のテストを表示するC#プログラムを作成しています。 テストには10の質問があります。 しかし、プログラムは、私は10 questions.Itがオンになった後、クイズが停止しないクイズを解決するたびに、10個の質問で質問の集まりが増加する
private void newToolStripMenuItem_Click (object sender, EventArgs e)
の助けを借りて、新しいクイズを選択した場合と同じアルゴリズムに従うことを望んでいない、それはで質問を繰り返し、一定の数の質問がブロックされます。
私はコードをステップ、と私は見た:
- を私は初めてのクイズ解決する場合:私は2番目の時間のためにそれを解決すると
questions.Count=10;
- を:
questions.Count=20;
- 私が解決したときにそれは3回目です:
questions.Count=30
;
私はどのように質問しますか?questions.Count=10
をどうすればいいですか?教えてください。ここで
は私のコードです:
public partial class Form3 : Form
{
int nr;
Collection<question> questions = new Collection<question>();
public class question
{
public bool displayed = false;
public string text;
}
//when I press a button from MenuStrip my quiz begin
private void newToolStripMenuItem_Click(object sender, EventArgs e)
{
nr = 1;
button1.Enabled = true;//it's the next_question button
StreamReader sr = new StreamReader("quiz.txt");
while (!sr.EndOfStream)
{
question i = new question();
questions.Add(i);
}
sr.Close();
int x = r.Next(questions.Count);
textBox1.Text = questionText;
questions[x].displayed = true;
current_question=x;
}
}
私は
private void newToolStripMenuItem_Click(object sender, EventArgs e)
の最初にこれを入れて、私は解決するすべてのクイズのため
Collection<question> questions = new Collection<question>()
を作成しようとしたことを追加します
または現在のクイズの最後に:
if (nr >= questions.Count){ //here }
これらの変更により、10個の質問でコレクションが増加することはありません。 ありがとうございました!
はそんなにありがとうを!できます! – Bogdan