查找 listA 是否包含不在 listB 中的任何元素 [英] Find if listA contains any elements not in listB

查看:22
本文介绍了查找 listA 是否包含不在 listB 中的任何元素的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有两个列表:

List<int> listA     
List<int> listB

如何使用 LINQ 检查 listA 中是否存在 listB 中不存在的元素?我可以使用 foreach 循环,但我想知道是否可以使用 LINQ

How to check using LINQ if in the listA exists an element wchich deosn't exists in the listB ? I can use the foreach loop but I'm wondering if I can do this using LINQ

推荐答案

listA.Except(listB) 会给你 listA 中所有不在 listB 中的项目

listA.Except(listB) will give you all of the items in listA that are not in listB

这篇关于查找 listA 是否包含不在 listB 中的任何元素的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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