0
有人可以告诉我发生了什么事吗?指数超出范围,必须是非负数,并小于集合的大小
我试图在Button1
被按下时在Label1
中出现一个随机问题。我只想让每个问题出现一次。
Dim Qtn(4) As String
Private Sub LoadQs()
Qtn(0) = "What is 1 + 10?"
Qtn(1) = "What is 1 + 11?"
Qtn(2) = "What is 1 + 12?"
Qtn(3) = "What is 1 + 13?"
Qtn(4) = "What is 1 + 14?"
End Sub
Private Sub RndQtn()
Dim list As New ArrayList
For i As Integer = 0 To 4
'Add the numbers to the collection.
list.Add(i)
Next i
Dim randomValue As New Random
Dim index As Integer
Dim item As Object
'Display the items in random order.
While list.Count > 0
'Choose a random index.
index = randomValue.Next(0, Qtn.Length)
'Get the item at that index.
item = list(index)
'Remove the item so that it cannot be chosen again.
list.RemoveAt(index)
'Display the item.
Label1.Text = Qtn(item)
End While
End Sub
欢迎来到Stack Overflow!我尽可能地猜测你的问题,然后编辑你的问题。但是,添加代码和说明以便更多知道该主题的人员将看到它。如果需要识别特定问题,请编辑您遇到的特定错误消息。看看[这个问题](http://stackoverflow.com/questions/2306742/index-was-out-of-range-must-be-non-negative-and-less-than-the-size-of -the-colle)。祝你好运! – manetsus