比较两个泛型列表 [英] Compare two generic Lists
本文介绍了比较两个泛型列表的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
您好,我怎么可以比较两个的列表的,第一类 ICollections< T>
其他列表< T>
看看他们使用的的LINQ
Hi ,how I can compare two Lists, the first type ICollections <T>
the other List<T>
see if they contain the same records
using Linq
推荐答案
假设的ICollection< T> X
和列表< T>是
...
如果记录事项的顺序:
return x.SequenceEqual(y);
如果顺序并不重要,我想你最好的选择是跳过LINQ和使用的HashSet< T>
:
If order doesn't matter, I think your best option is to skip LINQ and use a HashSet<T>
:
return new HashSet<T>(x).SetEquals(y);
这篇关于比较两个泛型列表的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文