C# 委托

 public delegate int ceshi(int a, int b);
        static int ax(int a, int b) {
            return a * b;
        }
        static int bx(int a, int b) {
            return a / b;
        }
        static void Main(string[] args)
        {
            ceshi wo;
            Console.WriteLine("请输入数");
            string c = Console.ReadLine();
            int d = c.IndexOf(" ");
            if (d > 0)
            {
                int a = Convert.ToInt32(c.Substring(0, d));
                int b = Convert.ToInt32(c.Substring(d + 1));
                Console.WriteLine("请输入M");
                c = Console.ReadLine();
                if (c.ToUpper() == "M")

                    wo = ax;


                else
                    wo = bx;

                Console.WriteLine(wo(a, b));
                Console.ReadKey();

            }
            else {
                Console.WriteLine("出来");
            
            }
            
        }

 

posted @ 2015-09-08 11:26  尘梦  阅读(158)  评论(0编辑  收藏  举报