Python与C#搜索集合
本文关键字:集合 搜索 Python | 更新日期: 2024-10-19 00:39:47
有没有一种简单的方法可以找到一个对象是否在C#中的集合中,就像Python在操作符中一样,我认为Linq会尽可能地接近你?
您可以尝试使用LinqAny()
,例如
// Whatever IEnumerable<T> collection
int[] source = new int[]
{1, 2, 3, 4};
// Put required criterium into Any()
Boolean has = source.Any(item => item == 3);
// You can put various criterium into Any(), not necessary ==:
Boolean hasNegatives = source.Any(item => item < 0);