c#委托之最大

  public delegate int ceshi(object o1, object o2);
        static void Main(string[] args)
        {
            string[] a = { "abCdeg", "ssxAf" };
            object [] b = { 2, 9, 5, 6 };
            object result=zhenga(a,gets);
            Console.WriteLine(result);
           
            
          
            Console.ReadKey();
        }
        public static int compare(object o1, object o2) 
        {
            int num1 = (int)o1;
            int num2 = (int)o2;
            return num1 - num2;
        }

        public static int gets(object o1, object o2) 
        {
            string num1 = (string)o1;
            string num2 = (string)o2;
            return num1.Length - num2.Length;
        }
        public static object zheng(object[] name,ceshi aaax)
        {

            object max = name[0];
            for (int i = 0; i < name.Length; i++)
            {
                //max-name[i]<0
                if (aaax(max,name[i])<0)
                {
                    max = name[i];
                }
            }
            return max;
        }
        public static object zhenga(object[] name, ceshi ce)
        {
            object names = name[0];
            for (int i = 0; i < name.Length; i++)
            {
                if (ce(name[i],names)>0)
                {
                    names = name[i];
                }

            }
            return names;


        }

  

posted @ 2016-05-24 09:11  尘梦  阅读(177)  评论(0编辑  收藏  举报