There are a couple of issues here. Firsly the Add
method takes a List(Of Integer)
but you are providing an Integer
. I'm not sure what collection you wanted to use there but it needs to be something other than i
.
Secondly when you say rows(cells(i).x)
it's indexing into the created rows
value but you haven't actually put anything into the list. You can only index into existing values which you haven't added yet.
Based on your comments I think the best data structure here is Dictionary(Of Integer, List(Of Integer))
. This will allow you to map the x
values to a collection of indexes that contain that value.
Dim map As New Dictionary(Of Integer, List(Of Integer))
For i = 0 To cells.Count -1
Dim x = cells(i).x
Dim list As List(Of Integer)
If Not map.TryGetValue(x, list) Then
list = New List(Of Integer)
map(x) = list
End If
list.Add(i)
Next
I don't think a List(Of List(Of Integer))
is appropriate because it would require that the x
values be contiguous and increasing to work properly. Maybe that's true here but I think it's unlikely