首页 > 代码库 > C#重载==和!=
C#重载==和!=
class A
{
public int P1 { get; set; }
public int P2 { get; set; }
public static bool operator !=(A a1, A a2)
{
return !a1.Equals(a2);
}
public static bool operator ==(A a1, A a2)
{
return a1.Equals(a2);
}
public override bool Equals(object obj)
{
// If parameter is null return false.
if(obj == null)
{
return false;
}
// If parameter cannot be cast to Settings return false.
A a2 = obj as A;
if((System.Object)a2 == null)
{
return false;
}
// Return true if the fields match:
if (P1 != a2.P1 || P2 != a2.P2)
return false;
else
return true;
}
public override int GetHashCode()
{
return P1;
}
}
C#重载==和!=
声明:以上内容来自用户投稿及互联网公开渠道收集整理发布,本网站不拥有所有权,未作人工编辑处理,也不承担相关法律责任,若内容有误或涉及侵权可进行投诉: 投诉/举报 工作人员会在5个工作日内联系你,一经查实,本站将立刻删除涉嫌侵权内容。