LINQ Except()方法不起作用 [英] LINQ Except() Method Does Not Work

查看:138
本文介绍了LINQ Except()方法不起作用的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有2个IList<T>类型的对象ItemsDTO.我想从另一个列表中排除一个列表.但是,这似乎对我不起作用,我想知道为什么吗?

I have 2 IList<T> of the same type of object ItemsDTO. I want to exclude one list from another. However this does not seem to be working for me and I was wondering why?

IList<ItemsDTO> related = itemsbl.GetRelatedItems();
IList<ItemsDTO> relating = itemsbl.GetRelatingItems().Except(related).ToList();

我正在尝试从relating列表中删除related中的项目.

I'm trying to remove items in related from the relating list.

推荐答案

由于类是引用类型,因此您的ItemsDTO类必须覆盖EqualsGetHashCode才能起作用.

Since class is a reference type, your ItemsDTO class must override Equals and GetHashCode for that to work.

这篇关于LINQ Except()方法不起作用的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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