这是有效的吗?
public struct MyStruct
{
public int Foo { get; set; }
public static bool operator ==(MyStruct a, MyStruct b)
{
return a.Equals(b);
}
public static bool operator !=(MyStruct a, MyStruct b)
{
return !a.Equals(b);
}
}
(我知道它的效率有点低,因为 Object.Equals 默认使用值类型的反射。但它有效吗?)
我问是因为 ReSharper 突出显示它并警告我MyStruct defines operator '==' or operator '!=' but does not provide 'Object.Equals(object o)' and 'Object.GetHashCode()'
。