我下面有课
using System;
using System.Collections.Generic;
namespace x
{
public class y : IEquatable<y>
{
public int a;
public int b;
public override bool Equals(object obj)
{
return Equals(obj as y);
}
public bool Equals(y other)
{
return other != null &&
a == other.a &&
b == other.b &&
}
public override int GetHashCode()
{
int hashCode = 1557084561;
hashCode = hashCode * -1521134295 +
EqualityComparer<string>.Default.GetHashCode(Name);
hashCode = hashCode * -1521134295 + a.GetHashCode();
hashCode = hashCode * -1521134295 + b.GetHashCode();
return hashCode;
}
}
}
我的问题是方法
public override int GetHashCode()
是否应该对应于方法public bool Equals(y other)
而不是Equals(object obj)
?我怎么知道。如果是这样,我如何对应它,因为我无法创建方法public bool override Equals(y other)
?