0

I've tried to search the forum to see if anyone has asked, but found nothing which is easily related to my question...

I'm wondering how I can loop through a list of public properties such as below:

Dim List1 As New List(Of GenericPlayerList)
Dim List2 As New List(Of GenericPlayerList)
Dim List3 As New List(Of GenericPlayerList)
Dim List4 As New List(Of GenericPlayerList)

So within my sub routine I can loop through each list and populate the class accordingly.

For example:

Public Class SelectTeam
Inherits System.Web.UI.Page

Dim List1 As New List(Of GenericPlayerList)
Dim List2 As New List(Of GenericPlayerList)
Dim List3 As New List(Of GenericPlayerList)
Dim List3 As New List(Of GenericPlayerList)


Private Sub PopulateDropDowns()

    'Loop through my lists
       Using db As PlayerEntities = New PlayerEntities()



       End Using


End Sub


End Sub

Public Class GenericPlayerList

    Public Property Surname As String
    Public Property Forename As String
    Public Property Nationality As String

End Class


End Class
4
  • Those are private fields. I think we need more information. Commented Jun 25, 2014 at 16:59
  • This property is defined within my page class so can be called within a sub routine in the same class. Commented Jun 25, 2014 at 17:02
  • Your question is not clear. Are you trying to populate the classes within the list? Or are you trying to populate a dropdownlist from the data that is already in the lists? Commented Jun 25, 2014 at 17:13
  • Sorry, I realise this isn't clear after re reading my question. I'm trying to populate each list (List1,List2 etc) from my database, all four lists have the same properties but the difference is each one will have different criteria which distinguishes them. For example list1 might be all male players, list2 all juniors. Commented Jun 25, 2014 at 17:22

1 Answer 1

1

Do you mean how to loop through each list? Like this?:

For Each item as GenericPlayerList in List1
    ' Do something with the item
Next

Or, perhaps you're trying to loop through the GenericPlayerList instances, since their name implies that they too are lists? (In which case the structure would be the same, just for each instance. Maybe even a nested loop?)

Or are you trying to loop through all of these four lists? In which case you have a few options. You might put them into a collection of their own (a lists of lists) and loop through that. Or perhaps use something like Union() and loop through the aggregate:

For Each item as GenericPlayerList in List1.Union(List2).Union(List3).Union(List4)
    ' Do something with the item
Next

Basically, you have a handful (potentially a list) of lists of what themselves appear to be lists. You can loop through any of these structures using the same For Each loop construct.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.