Setting an item in a Visual Basic list class when iterating with for each...
Posted on 2014-07-25
I'm trying to find a simple way to update the items in a list. When using For...Each the items do not actually get updated. See the following code...
Private Structure test
Dim iNum As Integer
Dim strStr As String
Private oTest As New List(Of test)
Dim newTest = New test
newTest.iNum = 1
newTest.strStr = "a"
For Each testItem As test In oTest
testItem.iNum = 2
At this point if I was to query the only item in the list, the value would still be (1, "a"). The list hasn't updated at this point. How can the list be modified?