Check if a value exists in the general list of values

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

So:

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

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

+5
source share
2 answers

In a more general case with LINQ (any type of abstract typed list is supported):

bool hasCar = myCars.Any(c => c.SomeID == testInt);
+17
source
myCars.Exists(c => c.SomeID == 10);
+7
source

All Articles