是否有内置方法来比较集合? [英] Is there a built-in method to compare collections?

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

问题描述

我想在我的 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天全站免登陆