【发布时间】:2012-03-26 09:45:57
【问题描述】:
我有一个公司类中的人员列表。
public class Company{
IList<Person> persons;
}
然后我有一个公司列表,
IList<Company> companies;
现在我有了一个名字(比如“Lasantha”)。如果此名称是公司中任何人姓名的一部分,我想找到该公司。我尝试使用 company.Contains() 方法。我在 Person 类中重写了 object.Equals 方法,如下所示,
public override bool Equals(object o)
{
var other = o as Person;
return this.Name.ToLower().Contains(other.Name.ToLower());
}
但这不起作用。它也没有调用这个 Equal 方法。谁能帮帮我。
谢谢。
【问题讨论】: