Reputation: 138
I am using vb.net to do this.
I would like to create a list (so that it can grow dynamically), in which each node has a fixed amount of fields. As follows:
node 1: name, surname, age.
node 2: name, surname, age.
...
node M: name, surname, age.
And so on, the number of times you need. That's why I need it to be a list so it can grow indefinitely.
What probe is to create as follows:
Private tableVirtual As New List (Of String) (11)
thinking that 11 is the amount of fields I need. (in my example they are only 3).
And try to add like this:
tableVirtual.Insert(tabla.Rows(i).Item(9).ToString, tabla.Rows(i).Item(0).ToString, tabla.Rows(i).Item(1).ToString, tabla.Rows(i).Item(2).ToString, tabla.Rows(i).Item(3).ToString, tabla.Rows(i).Item(4).ToString, tabla.Rows(i).Item(5).ToString, tabla.Rows(i).Item(6).ToString, tabla.Rows(i).Item(7).ToString, "", tabla.Rows(i).Item(8).ToString)
But it is not like that or I am not adding correctly.
Upvotes: 0
Views: 52
Reputation: 4439
So basically you want to create an object to refer to each person and their related information.
This is how you would define the object .. I'm assuming you're using a very recent version of Visual Stuio and .net ..
Private Class Person
Public Property FirstNames As String
Public Property Surname As String
Public Property Age As Integer
End Class
Next you want to create a list that can store objects of this type ..
Dim People As New List(Of Person)
Finally, the following method, will create a Person
object and add it to the list of People
Private Sub Test()
Dim tempPerson As New Person With {.FirstNames = "John", .Surname = "Doe", .Age = 32}
People.Add(tempPerson)
End Sub
Have a search for list tutorials in VB.net :)
Upvotes: 2