开发者

Check that value exists in a Generic List of Values

开发者 https://www.devze.com 2022-12-13 02:13 出处:网络
I am trying to figure out how to check if testInt exists in all Car.SomeID in List So: int testInt = 10;

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


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

bool hasCar = myCars.Any(c => c.SomeID == testInt);


myCars.Exists(c => c.SomeID == 10);
0

精彩评论

暂无评论...
验证码 换一张
取 消