I have this situation: every time I load a name and an age I put them in a separate arraylist, after that, I want it to show me the data that it loads (name, age), something like "the person's name is ... and he's... years old"
Next, the subroutine where I do that. I did it with two for each, which makes the data repeat.
Sub MostrarListado(ByRef arrayNombre As ArrayList, ByRef arrayEdad As ArrayList)
For Each nombre In arrayNombre
For Each edad In arrayEdad
Console.WriteLine("La persona se llama: " & nombre)
Console.WriteLine("y tiene: " & edad & " " & "anos")
Next
Next
End Sub
If you do a double you
For Each
will show each name with all the ages stored and not with the age that corresponds to it. Your code assumes that bothArrayList
contain the same number ofItems
and that each name corresponds to the age stored inArrayList arrayEdad
it in the same index, assuming that this is always true, the following code should work well, I recommend that you try it and tell me the result.Edition: Next I put another variant making a bow
For
.