Check that value exists in a Generic List of Values
Asked Answered
K

2

6

I am trying to figure out how to check if testInt exists in all Car.SomeID in List

So:

int testInt = 10;
List<Car> myCars = GetCars();

I want to see if there is a match on 10 in any of myCards.SomeID

Koel answered 4/12, 2009 at 16:57 Comment(0)
T
18

In the more general case, with LINQ (supports any type of abstract typed list):

bool hasCar = myCars.Any(c => c.SomeID == testInt);
Turnkey answered 4/12, 2009 at 17:0 Comment(0)
J
7
myCars.Exists(c => c.SomeID == 10);
Joella answered 4/12, 2009 at 16:59 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.