A
Adam
Hi all,
In my VB.NET code below, I try to change the user name in my arraylist from
Ted to Bob, but instead it adds a new user to the arraylist named Bob. Can
anyone explain why this happens and how I might modify a structure in an
arraylist without having to completely remove it and re-add the structure to
the arraylist? I just want to iterate throught the arraylist and change
items based on certain conditions.
Thanks in advance!
Public Structure user
Dim name As String
End Structure
Module Module1
Dim users As ArrayList = New ArrayList
Dim ouser As user
Sub Main()
ouser.name = "Ted"
users.Add(ouser)
For Each ouser In users
ouser.name = "Bob"
Next
users.Add(ouser)
For Each ouser In users
Console.WriteLine(ouser.name)
Next
Console.ReadLine()
End Sub
End Module
In my VB.NET code below, I try to change the user name in my arraylist from
Ted to Bob, but instead it adds a new user to the arraylist named Bob. Can
anyone explain why this happens and how I might modify a structure in an
arraylist without having to completely remove it and re-add the structure to
the arraylist? I just want to iterate throught the arraylist and change
items based on certain conditions.
Thanks in advance!
Public Structure user
Dim name As String
End Structure
Module Module1
Dim users As ArrayList = New ArrayList
Dim ouser As user
Sub Main()
ouser.name = "Ted"
users.Add(ouser)
For Each ouser In users
ouser.name = "Bob"
Next
users.Add(ouser)
For Each ouser In users
Console.WriteLine(ouser.name)
Next
Console.ReadLine()
End Sub
End Module