コード例 #1
0
        //public static void T1()
        //{
        //    Console.WriteLine("我是T1");
        //}

        //public static void T2()
        //{
        //    Console.WriteLine("我是T2");
        //}
        //public static void T3()
        //{
        //    Console.WriteLine("我是T3");
        //}
        //public static void T4()
        //{
        //    Console.WriteLine("我是T4");
        //}
        #endregion

        #region 泛型委托
        //public static T GetMax<T>(T[] nums,DelConpare<T> del)
        //{
        //    T max = nums[0];
        //    for (int i = 0; i < nums.Length; i++)
        //    {
        //        if (del(max,nums[i])<0)
        //        {
        //            max = nums[i];
        //        }
        //    }
        //    return max;
        //}

        //public static int Comparel(int n1,int n2)
        //{
        //    return n1 - n2;
        //}
        #endregion

        #region 委托
        //public static void Test(string name, DelSayHi del)
        //{
        //    del(name);
        //}

        //public static void SayHelloChinese(string name)
        //{
        //    Console.WriteLine("吃了吗" + name);

        //}
        //public static void SayHelloEnglish(string name)
        //{
        //    Console.WriteLine("Nice to meet you" + name);
        //}
        #endregion

        #region 加减乘除
        public static CalFather GetCal(string opera, double n1, double n2)
        {
            CalFather cal = null;

            switch (opera)
            {
            case "+": cal = new Add(n1, n2);
                break;

            case "-":
                cal = new Sub(n1, n2);
                break;

            case "*":
                cal = new Cheng(n1, n2);
                break;

            case "/":
                cal = new Chu(n1, n2);
                break;
            }
            return(cal);
        }
コード例 #2
0
        static Operation GetOperation(string oper, int n1, int n2)
        {
            Operation operation = null;

            switch (oper)
            {
            case "+":
                operation = new Add(n1, n2);
                break;

            case "-":
                operation = new Sub(n1, n2);
                break;

            case "*":
                operation = new Cheng(n1, n2);
                break;

            case "/":
                operation = new Chu(n1, n2);
                break;
            }
            return(operation);
        }