是否有一个内置的方法在C#比较集合? [英] Is there a built-in method to compare collections in C#?
问题描述
我想在我的Equals方法比较一对夫妇收藏的内容。我有一个字典和一个IList。是否有一个内置的方法来做到这一点?
I would like to compare the contents of a couple of collections in my Equals method. I have a Dictionary and an IList. Is there a built-in method to do this?
编辑: 我想比较两个字典和两个ILists,所以我认为相等的意思是明确的 - 如果两个字典包含映射到相同的值相同的密钥,那么他们是平等的。
Edited: I want to compare two Dictionaries and two ILists, so I think what equality means is clear - if the two dictionaries contain the same keys mapped to the same values, then they're equal.
推荐答案
<一个href="http://msdn.microsoft.com/en-us/library/bb342073.aspx"><$c$c>Enumerable.SequenceEqual$c$c>
确定两个序列是否相等通过使用指定的IEqualityComparer(T)比较其内容。
Determines whether two sequences are equal by comparing their elements by using a specified IEqualityComparer(T).
您不能直接比较的清单和放大器;字典,但你可以从字典中值的列表,列表比较
You can't directly compare the list & the dictionary, but you could compare the list of values from the Dictionary with the list
这篇关于是否有一个内置的方法在C#比较集合?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!