有内置的方法可以比较集合吗? [英] Is there a built-in method to compare collections?

查看:76
本文介绍了有内置的方法可以比较集合吗?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

编辑:
我想比较两个字典和两个IList,所以我认为相等的含义很清楚-如果两个字典包含映射到相同值的相同键,则它们相等。

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

这篇关于有内置的方法可以比较集合吗?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆