我已经过了question次了
我明白,要落实==
、!=
、Equals()
.
public class BOX
{
double height, length, breadth;
// this is first one '=='
public static bool operator== (BOX obj1, BOX obj2)
{
return (obj1.length == obj2.length
&& obj1.breadth == obj2.breadth
&& obj1.height == obj2.height);
}
// this is second one '!='
public static bool operator!= (BOX obj1, BOX obj2)
{
return !(obj1.length == obj2.length
&& obj1.breadth == obj2.breadth
&& obj1.height == obj2.height);
}
// this is third one 'Equals'
public override bool Equals(BOX obj)
{
return (length == obj.length
&& breadth == obj.breadth
&& height == obj.height);
}
}
我想,我已经正确地编写了覆盖==
!=
Equals
个运算符的代码.不过,我得到的编译错误如下.
'myNameSpace.BOX.Equals(myNameSpace.BOX)' is marked as an override
but no suitable method found to override.
所以,问题是——如何覆盖上述运营商&;摆脱这个错误?