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
List < string > list1 = new List < string > () { "Lawrence", "Adams", "Pitt", "Tom" }; Now use the Contains method to check if an item exits in a list or not.
bool containsItem = myList. Any(item => item. UniqueProperty == wonderIfItsPresent. UniqueProperty);
In the more general case, with LINQ (supports any type of abstract typed list):
bool hasCar = myCars.Any(c => c.SomeID == testInt);
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With