Asp.net 将ForEach循环与ListItems组合
我有几个ForEach循环,它们循环检索每个复选框列表中的复选框。我试图理解/弄明白的是如何将ForEach循环组合成一个循环。下面是我目前拥有和正在工作的东西Asp.net 将ForEach循环与ListItems组合,asp.net,vb.net,Asp.net,Vb.net,我有几个ForEach循环,它们循环检索每个复选框列表中的复选框。我试图理解/弄明白的是如何将ForEach循环组合成一个循环。下面是我目前拥有和正在工作的东西 For Each li As ListItem In allocationCheckList.Items customReportQueries(li.Value, li.Text, li) Next For Each li As ListItem In clientSpecificList.I
For Each li As ListItem In allocationCheckList.Items
customReportQueries(li.Value, li.Text, li)
Next
For Each li As ListItem In clientSpecificList.Items
customReportQueries(li.Value, li.Text, li)
Next
For Each li As ListItem In dataStructureList.Items
customReportQueries(li.Value, li.Text, li)
Next
您可以这样合并: 调用块:
Private Sub SomeSub()
customReportQueries(allocationCheckList.Items)
customReportQueries(clientSpecificList.Items)
customReportQueries(dataStructureList.Items)
End Sub
更改customReportQueries子例程
Private Sub customReportQueries(checkBoxList As ListItemCollection)
For Each li As ListItem In checkBoxList
'Do what the old customReportQueries Subroutine did
Next
End Sub
您可以这样合并: 调用块:
Private Sub SomeSub()
customReportQueries(allocationCheckList.Items)
customReportQueries(clientSpecificList.Items)
customReportQueries(dataStructureList.Items)
End Sub
更改customReportQueries子例程
Private Sub customReportQueries(checkBoxList As ListItemCollection)
For Each li As ListItem In checkBoxList
'Do what the old customReportQueries Subroutine did
Next
End Sub
您可以
Dim-boxLists={allocationCheckList,clientSpecificList,dataStructureList}
(如果有意义的话,甚至可以使用它们的.Lists
属性)并在该数组上迭代。如果您所拥有的有效,那么为什么要组合它们?这难道不会降低它的可读性吗?你可以Dim-boxLists={allocationCheckList,clientSpecificList,dataStructureList}
(如果有意义的话,甚至可以使用它们的.Lists
属性)并在该数组上进行迭代。如果你所做的一切都有效,那么你为什么要组合它们呢?这会不会让它变得不那么可读?谢谢你的帮助。这正是我想要的。谢谢你的帮助。这正是我要找的。