相关疑难解决方法(0)

运算符重载==,!=,等于

我已经经历了一个问题

我明白,有必要实施==,!=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 …
Run Code Online (Sandbox Code Playgroud)

.net c# compiler-errors operator-overloading

49
推荐指数
4
解决办法
7万
查看次数

标签 统计

.net ×1

c# ×1

compiler-errors ×1

operator-overloading ×1