Naad Dyr Naad Dyr - 5 months ago 16
Vb.net Question

add a list into another list in vb.net

I have a list as follows and I want to add it in another list:

Dim listRecord As New List(Of String)
listRecord.Add(txtRating.Text)
listRecord.Add(txtAge.Text)
listRace.Add(listRecord)


to obtain something like
{{r1,a1},{r2,a2},{r3,a3}}
, how can I achieve this in VB.Net?

Answer

I assume from your question you want nested Lists, not to simply append one list onto the end of another?

Dim listRecord As New List(Of String)
listRecord.Add(txtRating.Text)
listRecord.Add(txtAge.Text)
listRace.Add(listRecord)

Dim records as new List(of List(of String))
records.Add(listRecord)

Hope this helps

Update
Reading them is like accessing any other list.
To get the first field in the first record

return records(0)(0)

second field in first record

return records(0)(1)

etc . . .

Comments