检查值是否存在于通用值列表中 [英] Check that value exists in a Generic List of Values

查看:81
本文介绍了检查值是否存在于通用值列表中的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试找出如何检查List中所有Car.SomeID中是否存在testInt

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

所以:

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

我想查看任何myCards.SomeID中是否有10个匹配项

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

推荐答案

在更一般的情况下,使用LINQ(支持任何类型的抽象类型列表):

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

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

这篇关于检查值是否存在于通用值列表中的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆