List1 in the following example is a SortedList(Of MyClass) and contains 251 members.
The first two codeblocks execute in 15.5 seconds.
1:
For cnt As Integer = 1 To 1000000
For Each TempDE In List1
Dim F As String = TempDE.Key
TempDE.Value.x1 = 444
Next
Next
2:
For cnt As Integer = 1 To 1000000
For Each TempDE As KeyValuePair(Of String, phatob) In List2
Dim F As String = TempDE.Key
TempDE.Value.x1 = 444
Next
Next
This one executes in 5.6 seconds:
For cnt As Integer = 0 To 999999
For cnt2 As Integer = 0 To 250
Dim F As String = List1.Keys(cnt2)
List1.Values(cnt2).x1 = 444
Next
Next
Why are the first two codeblocks so much slower?
Thanks.
Edit: modified line 1 to read 251 members