Example #1
0
        //二元操作符
        public static LimitedInt operator -(LimitedInt x, LimitedInt y)
        {
            LimitedInt li = new LimitedInt();

            li.TheValue = x.TheValue - y.TheValue;
            return(li);
        }
Example #2
0
        public static LimitedInt operator +(LimitedInt x, double y)
        {
            LimitedInt li = new LimitedInt();

            li.TheValue = x.TheValue + (int)y;
            return(li);
        }
Example #3
0
        //-一元操作符
        public static LimitedInt operator -(LimitedInt x)
        {
            LimitedInt li = new LimitedInt();

            li.TheValue = 0;
            return(li);
        }
Example #4
0
        public CH0402()
        {
            LimitedInt li1 = new LimitedInt();
            LimitedInt li2 = new LimitedInt();
            LimitedInt li3 = new LimitedInt();

            li1.TheValue = 10;
            li2.TheValue = 26;
            Console.WriteLine($"l11:{li1.TheValue},li2:{li2.TheValue}");
            li3 -= li1;
            Console.WriteLine($"l11:{li1.TheValue},li3:{li3.TheValue}");
            li3 = li1 - li2;
            Console.WriteLine($"{li1.TheValue}-{li2.TheValue}={li3.TheValue}");
        }