所以编译器不允许我重载我类的 == 和 != 运算符。下面是这个类的样子:
public class Item
{
public string _name;
public double _weight;
public decimal _wholesalePrice;
public int _quantity;
public Item(string name, double weight, decimal wholesalePrice, int quantity)
{
_name = name;
_weight = weight;
_wholesalePrice = wholesalePrice;
_quantity = quantity;
}
public static override bool operator ==(Item left, Item right)
{
if (left._name == right._name)
{
return true;
}
return false;
}
public static override bool operator !=(Item left,Item right)
{
return !(left == right);
}
}
编译器一直告诉我“修饰符 'override' 对此项目无效。起初我以为我可能没有将基方法声明为虚拟,但我的类没有派生。任何想法发生了什么?