我如何确保列表< T>。载有(T)的作品与我的自定义类? [英] How do i make sure that List<T>.Contains(T) works with my custom class?

查看:154
本文介绍了我如何确保列表< T>。载有(T)的作品与我的自定义类?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我使用.NET 2.0(C#)

I use .net 2.0 (C#)

我有一个Person类,我pupulate名单<人>从数据库页。

I have a Person class, and i pupulate List< Person> p from the database.

我知道一个事实,我的列表中有重复,但是当我尝试的删除重复他们没有得到清除。

i know for a fact that my list has duplicates, but when i try to remove the duplicates they don't get removed.

我的Person类需要实现列表与LT任何接口; T>。载有(T)正常工作?

Does my Person class need to implement any interfaces for List< T>.Contains(T) to work properly?

任何其他的想法?

感谢您。

推荐答案

您Person类应该实现 IEquatable

Your Person class should implement IEquatable

这篇关于我如何确保列表&LT; T&GT;。载有(T)的作品与我的自定义类?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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