你能帮我解决这个问题吗:
我有 5 个字符串列表,比如说 A、B、C、D 和 E:
A has 6 items
B has 5 items
C has 9 items
D has 2 items
E has 7 items
我需要排序或查找“C”作为具有最大项目的列表。
我需要在 winform 中创建选项卡,并且在我需要以编程方式创建 datagridview 的每个选项卡上。列表中的最大计数将是我需要创建的最大选项卡。并且在每个选项卡上,每个列表成员都会有 1 个项目。当然,并非所有选项卡都会有来自成员的项目数量较少的项目。
以前我所做的是遍历表和数据网格来构建和解决问题,以避免对列表进行排序,因为我不知道在这些列表中找到最大项目。
更新:由安德鲁帮助
` Dim z As New List(Of List(Of String))
Dim a As New List(Of String)
a.Add("a1")
a.Add("a2")
a.Add("a3")
Dim b As New List(Of String)
b.Add("b1")
b.Add("b2")
b.Add("b3")
b.Add("b4")
b.Add("b5")
Dim c As New List(Of String)
c.Add("c1")
c.Add("c2")
c.Add("c3")
c.Add("c3")
z.Add(a)
z.Add(b)
z.Add(c)
Dim maxItems = z.Max(Function(p) p.Count)
MessageBox.Show(maxItems)`
如果您只需要最长列表的长度...
Private A As New List(Of String) From {"Mathew", "Mark", "Luke", "John"}
Private B As New List(Of String) From {"Apples", "Oranges", "Pears"}
Private C As New List(Of String) From {"Haddock", "Salmon"}
Private D As New List(Of String) From {"Great Dane", "Poodle", "Bulldog", "Spaniel", "Golden Retriever"}
Private Sub GetMaxListLength()
Dim E() As Integer = {A.Count, B.Count, C.Count, D.Count}
Dim max = E.Max
MessageBox.Show(max.ToString)
End Sub
本文收集自互联网,转载请注明来源。
如有侵权,请联系[email protected] 删除。
我来说两句