本文介绍了SequenceEqual特定的属性的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想比较对象的两个列表。的对象有四个不同的性质。我只需要三个人来比较的序列(只有三个,因为一个总是有所不同)。

I would like to compare two lists of objects. The objects have four different properties. I need to compare only three of them as sequence (only three because one is always different).

一个例子是如下:

list1 = new List<myClass>() { new myClass(10, "a", 100, "unique1"),
    new myClass(10, "a", 100, "unique2") };

list2 = new List<myClass>() { new myClass(10, "a", 100, "unique3"),
    new myClass(10, "a", 100, "unique4") };



我可以比较那些列为序列而无需对第四(唯一)的财产?对于exapmle期望中的结果将是TRUE。

Can I compare those lists as sequence without the fourth (unique) property? Desired result for the exapmle would be TRUE.

任何想法如何解决这个问题?

Any ideas how to solve this?

推荐答案

您可以使用过载,使您可以在传递一个的IEqualityComparer< T> 实现,仅包括要比较的属性。

You could use the SequenceEqual overload that allows you to pass in an IEqualityComparer<T> implementation that only includes the properties that you wish to compare.

连结网页上的例子是一个很好的一个。

这篇关于SequenceEqual特定的属性的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!