vb.net中对同一arrayList的顺序搜索

vb.net中对同一arrayList的顺序搜索,vb.net,arraylist,sequential,Vb.net,Arraylist,Sequential,我将updatedDetailList作为一个列表,我希望迭代并获取当前和下一个对象值,并比较这两个值。如果在updatedDetailList中找到相同的PROD\u ID,则将matchFound返回为TRUE 是否有任何方法可以获取内部For循环中的下一个对象。像 Public Function Validate(updatedDetailList As List(Of DetailVO)) As Boolean Dim matchFound As Boolean = False

我将
updatedDetailList
作为一个列表,我希望迭代并获取当前和下一个对象值,并比较这两个值。如果在
updatedDetailList
中找到相同的
PROD\u ID
,则将
matchFound
返回为
TRUE

是否有任何方法可以获取内部For循环中的下一个对象。像

Public Function Validate(updatedDetailList As List(Of DetailVO)) As Boolean
  Dim matchFound As Boolean = False

  For Each firstUpdatedDetail In updatedDetailList
    For Each nextUpdatedDetail In updatedDetailList
      If firstUpdatedDetail.PROD_ID.Equals(nextUpdatedDetail.PROD_ID) Then
        matchFound = True
      End If
    Next nextUpdatedDetail
  Next firstUpdatedDetail

  Return matchFound
End Function

似乎您正在尝试执行不同的验证,因此
updatedDetailList
的每一项都必须是唯一的

在不改变方法的情况下(即使用
For
循环),代码如下:

For Each firstUpdatedDetail In **updatedDetailList**
  For Each nextUpdatedDetail In **updatedDetailList.Next**
    If firstUpdatedDetail.PROD_ID.Equals(nextUpdatedDetail.PROD_ID) Then
      matchFound = True
    End If
  Next nextUpdatedDetail
Next firstUpdatedDetail
但是有一种更快的方法来执行相同的操作—它使用LINQ:

For i = 0 to updatedDetailList.Count - 2
  If updatedDetailList(i).PROD_ID.Equals(updatedDetailList(i+1).PROD_ID) Then
    matchFound = True
    Exit For
  End If
Next
Dim matchFound As Boolean=updatedDetailList.Distinct.Count updatedDetailList.Count

我在寻找这个答案。。对于i=0到updatedTurnDetailList.Count-1对于j=i+1到updatedTurnDetailList.Count-1如果updatedTurnDetailList(i).PROD\u ID.Equals(updatedTurnDetailList(j).PROD\u ID)然后matchFound=如果下一步结束,则退出Next@user1733547:那么您肯定需要查看我的最后一个示例(一行代码)。或者创建一本字典——它会更具可读性。创建一个双循环来验证唯一性不是一个好方法,除非您被困在纯C中:)
Dim matchFound As Boolean = updatedDetailList.Distinct.Count <> updatedDetailList.Count