什么是包含和任何在LINQ的区别? [英] What is the difference between Contains and Any in LINQ?
本文介绍了什么是包含和任何在LINQ的区别?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
什么是之间的差异蕴含
和任何
在LINQ?似乎无法找到找到它的任何文件。
What is the difference between Contains
and Any
in LINQ? Can't seem to find to find any documentation on it.
推荐答案
包含
需要一个对象,任何
函数取一个判断。
Contains
takes an object, Any
takes a predicate.
您使用包含
是这样的:
listOFInts.Contains(1);
和任何
是这样的:
listOfInts.Any(i => i == 1);
listOfInts.Any(i => i % 2 == 0); // Check if any element is an Even Number
所以,如果你想检查特定的条件下,使用任何
。如果你想检查元素的存在,使用包含
。
So if you want to check for a specific condition, use Any
. If you want to check for the existence of an element, use Contains
.
这篇关于什么是包含和任何在LINQ的区别?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文