需要复写自定义类的Equlas函数
以下只取code是否相等来判断,也可以取全部属性进行判断
public class OutCode
{
string code;
string ct;
public OutCode(string vcode,string vct)
{
this.code = vcode;
this.ct = vct;
}
public string Code
{
get {
return code;
}
set{
code=value;
}
}
public string Ct
{
get {
return ct;
}
set {
ct = value;
}
}
/// <summary>
/// 描 述:Code对象相等,自定义比较
/// 作 者:Shawn
/// 创建日期:2013-06-26
/// </summary>
public Boolean Equals(OutCode other)
{
if (this.code.Equals(other.code))
{
return true;
}
else
{
return false;
}
}
//自定义类型调用remove和find等有比较行为时,需要复写Equals()和gethashcode()
public override bool Equals(object obj)
{
return (obj is OutCode) && Equals((OutCode)obj);
}
public override int GetHashCode()
{
return this.code.GetHashCode();
}
}