User-1427396445 posted
I have some basic code to fill items in an ArrayList as follows:
Dim intSteps As ArrayList = New ArrayList()
Select Case Session("type")
Case 1
intSteps.Add(0)
intSteps.Add(1)
intSteps.Add(2)
intSteps.Add(6)
intSteps.Add(11)
intSteps.Add(12)
Case 2
intSteps.Add(0)
intSteps.Add(1)
intSteps.Add(2)
intSteps.Add(5)
intSteps.Add(6)
intSteps.Add(11)
intSteps.Add(12)
Case Else
intSteps.Add(0)
intSteps.Add(1)
intSteps.Add(2)
intSteps.Add(3)
intSteps.Add(4)
intSteps.Add(5)
intSteps.Add(6)
intSteps.Add(7)
intSteps.Add(8)
intSteps.Add(9)
intSteps.Add(10)
intSteps.Add(11)
intSteps.Add(12)
End Select
Dim j As Integer
For j = 0 To intSteps.Count - 1
Response.Write(intSteps.IndexOf(j) & " : " & intSteps.Item(j) & "<br />")
Next
The issue is that for Case 1 the output is:
0 : 0
1 : 1
2 : 2
-1 : 6
-1 : 11
-1 : 12
For Case 2, it's:
0 : 0
1 : 1
2 : 2
-1 : 5
-1 : 6
3 : 11
4 : 12
And for Else, it's:
0 : 0
1 : 1
2 : 2
3 : 3
4 : 4
5 : 5
6 : 6
7 : 7
8 : 8
9 : 9
10 : 10
11 : 11
12 : 12
Why is the index being set as -1 for a few items?