是否有一个内置的方法在C#比较集合?有一个、方法

由网友(荆棘鸟)分享简介:我想在我的Equals方法比较一对夫妇收藏的内容。我有一个字典和一个IList。是否有一个内置的方法来做到这一点?I would like to compare the contents of a couple of collections in my Equals method. I have a Diction...

我想在我的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.

推荐答案

Enumerable.SequenceEqual

确定两个序列是否相等通过使用指定的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

阅读全文

相关推荐

最新文章