我试图搜索论坛,看是否有人问过,但没有发现任何与我的问题相关的内容...
我想知道如何循环浏览公共属性列表,如下所示:
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)
因此,在我的子例程中,我可以循环遍历每个列表并相应地填充类。
例如:
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
答案 0 :(得分:1)
您的意思是如何遍历每个列表?像这样?:
For Each item as GenericPlayerList in List1
' Do something with the item
Next
或许,您可能正在尝试遍历GenericPlayerList
个实例,因为他们的名字暗示它们也是列表? (在这种情况下,结构将是相同的,仅适用于每个实例。甚至可能是嵌套循环?)
或者您是否尝试遍历这四个列表中的所有?在这种情况下,您有几个选择。您可以将它们放入自己的集合(列表列表)中并循环使用它们。或者也许使用something like Union()
并循环聚合:
For Each item as GenericPlayerList in List1.Union(List2).Union(List3).Union(List4)
' Do something with the item
Next
基本上,您有一些(可能是一个列表)列表,列出了自己似乎是列表的内容。您可以使用相同的For Each
循环结构遍历任何这些结构。