Joe
Joe

Reputation: 551

Loop through a complex list using linq in VB.net

I have a field called LotNo and a List(Of LotDTO) called LotsList that has among other properties a LotNumber() property both of type string.

This if statement is not working If (LotsList.Contains(selectedLot.LotNo) Then … because I am obviously comparing a complex object to a string so what is the correct way?

Upvotes: 1

Views: 93

Answers (1)

jmcilhinney
jmcilhinney

Reputation: 54427

If LotsList.Any(Function(lot) lot.LotNo = selectedLot.LotNo) Then

The Any extension method will tell whether any items in a list satisfy an arbitrary Boolean condition.

Upvotes: 2

Related Questions