什么是检查两个List&LT的最佳途径; T>在C#中的平等名单 [英] What is the best way to check two List<T> lists for equality in C#

查看:122
本文介绍了什么是检查两个List&LT的最佳途径; T>在C#中的平等名单的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

有很多方法可以做到这一点,但我觉得我已经错过了一个函数或东西。



显然列表==列表将使用的Object.Equals()并返回



如果列表中的每一个元素都是平等的,存在于相反的列表中的同一个位置,然后我会认为他们是平等的。我使用的是值类型,而是一个正确实施数据对象应以相同的方式工作(即我不是在寻找一个浅拷贝名单,只是说的值的每个对象的的范围内是相同的)。



我试着寻找有类似的问题,但我的问题是每一个元素的平等,在正确的顺序。


解决方案

  Enumerable.SequenceEqual< TSource> 

MSDN


There are many ways to do this but I feel like I've missed a function or something.

Obviously List == List will use Object.Equals() and return false.

If every element of the list is equal and present in the same location in the opposite list then I would consider them to be equal. I'm using value types, but a correctly implemented Data object should work in the same fashion (i.e I'm not looking for a shallow copied list, only that the value of each object within is the same).

I've tried searching and there are similar questions, but my question is an equality of every element, in an exact order.

解决方案

Enumerable.SequenceEqual<TSource>

MSDN

这篇关于什么是检查两个List&LT的最佳途径; T&GT;在C#中的平等名单的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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