0
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反復して現在と次のオブジェクト値を取得し、両方の値を比較したいリストとして持っています。で同じものを見つけた場合PROD_IDは、としてupdatedDetailList返します。matchFoundTRUE

内側の 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
4

1 に答える 1

1

個別の検証を実行しようとしているように見えるため、のすべてのアイテムはupdatedDetailList一意である必要があります。

アプローチを変更せずに(つまり、Forループを使用して)、コードは次のとおりです。

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

しかし、同じことをより速く実行する方法があります - LINQ を使用します:

Dim matchFound As Boolean = updatedDetailList.Distinct.Count <> updatedDetailList.Count
于 2012-10-30T23:28:30.130 に答える