如果重复项已经在列表中,那么您可以通过以下方式检测它们:
Class DemoClass
Public Property amount As Decimal
Public Property number As String
Public Property [date] As Date
End Class
Private Sub Button2_Click(sender As System.Object, e As System.EventArgs) Handles Button2.Click
Dim lstSource As New List(Of DemoClass)
lstSource.Add(New DemoClass With {.amount = 121, .number = "121", .date = #1/1/2012#})
lstSource.Add(New DemoClass With {.amount = 122, .number = "122", .date = #1/2/2012#})
lstSource.Add(New DemoClass With {.amount = 123, .number = "123", .date = #1/3/2012#})
lstSource.Add(New DemoClass With {.amount = 124, .number = "124", .date = #1/4/2012#})
lstSource.Add(New DemoClass With {.amount = 125, .number = "125", .date = #1/5/2012#})
lstSource.Add(New DemoClass With {.amount = 126, .number = "126", .date = #1/6/2012#})
lstSource.Add(New DemoClass With {.amount = 127, .number = "127", .date = #1/7/2012#})
lstSource.Add(New DemoClass With {.amount = 128, .number = "123", .date = #1/8/2012#}) 'dup'
lstSource.Add(New DemoClass With {.amount = 129, .number = "129", .date = #1/9/2012#})
lstSource.Add(New DemoClass With {.amount = 130, .number = "130", .date = #1/10/2012#})
lstSource.Add(New DemoClass With {.amount = 131, .number = "122", .date = #1/11/2012#}) 'dup'
lstSource.Add(New DemoClass With {.amount = 132, .number = "132", .date = #1/12/2012#})
For intOuter As Integer = 0 To lstSource.Count - 2
For intInner As Integer = intOuter + 1 To lstSource.Count - 1
If lstSource(intOuter).number = lstSource(intInner).number Then
'duplicate found
MsgBox("Duplicate found: " & lstSource(intOuter).number)
End If
Next intInner
Next intOuter
End Sub