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

查看:406
本文介绍了查找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天全站免登陆