Question

Hello this is my first time posting so bear with me if I'm not so on point. Here is my question:

I'm trying to create a list within a list in asp.net, something like

 callList(a).part(b).Number
 callList(a).part(b).Desc

I have service calls and each of these calls can have multiple parts listed in them. Right now the class structure is something like

 public class calls

 somevars.....

      public class part

           public Number as integer
           public desc as String

       end class
 end class

To create the call themselves I have

 callList As New List(Of calls)
 callList.add(calls)

How would I add multiple parts for each call?

Was it helpful?

Solution

Maybe this is what you are looking for. I used different names, but you'll figure it out :)

    Public Class clsContent
        Public Name As String
        Public listOfCounteries As List(Of clsCountry)
    End Class

    Public Class clsCountry
        Public countryName As String
    End Class

    Class Program
        Private Shared Sub Main(args As String())

            Dim _countryEgypt As New clsCountry()
            _countryEgypt.countryName = "Egypt"

            Dim _countrySudan As New clsCountry()
            _countrySudan.countryName = "Sudan"

            Dim _cont As New clsContent()
            _cont.Name = "Africa"
            _cont.listOfCounteries = New List(Of clsCountry)()
            _cont.listOfCounteries.Add(_countryEgypt)
            _cont.listOfCounteries.Add(_countrySudan)


            Dim _listOfContenents As New List(Of clsContent)()
            _listOfContenents.Add(_cont)


            Console.WriteLine((("Contenent: " + _listOfContenents(0).Name & " Country 1: ") + _listOfContenents(0).listOfCounteries(0).countryName & " Country 2: ") + _listOfContenents(0).listOfCounteries(1).countryName)


    Console.Read()
    End Sub
End Class

OTHER TIPS

I think what you're looking for is described here under nested lists (slight syntax changes for ASP.net vs VB.net) add a list into another list in vb.net


EDIT: If you have trouble with the link, what you'll find there is:

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 . . .

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)

He creates a

List(Of String)

and then adds it to a

List(Of List(Of String))
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top