Exemple #1
0
        public static AddClass1 operator -(AddClass1 op1)
        {
            AddClass1 returnVal = new AddClass1();

            returnVal.Val = -op1.Val;
            return(returnVal);
        }
Exemple #2
0
        //重载+
        public static AddClass1 operator +(AddClass1 op1, AddClass1 op2)
        {
            AddClass1 returnVal = new AddClass1();

            returnVal.Val = op1.Val + op2.Val;
            return(returnVal);
        }
Exemple #3
0
        static void Main(string[] args)
        {
            AddClass1 op1 = new AddClass1();

            op1.Val = 1;
            AddClass1 op2 = new AddClass1();

            op2.Val = 2;
            AddClass1 op3 = op1 + op2;

            Console.WriteLine("op3.Var={0}", op3.Val);


            AddClass2 op4 = new AddClass2();

            op4.Val = 10;
            AddClass3 op5 = op1 + op4;

            Console.WriteLine("op5.Var={0}", op5.Val);

            Console.ReadKey();
        }