c#之委托所有方法

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace ConsoleApplication3
{
    public delegate void ceshi(string[] names);
    class Program
    {
        static void Main(string[] args)
        {
            string[] a = { "abCdeg", "ssxAf" };

            //第一种
            //ProStrSYH(a);
            //ProStrToLower(a);
            //ProStToUpper(a);
            //ceshi aaax = new ceshi(ProStToUpper);
            //for (int i = 0; i < a.Length; i++) 
            //{
            //    Console.WriteLine(a[i]);
            //}

            //第二种
            //ceshi aX = ProStToUpper;
            //aX(a);

            //第三种
            //ceshi sayhi = delegate(string[] names)
            //{
            //    for (int i = 0; i < a.Length; i++)
            //    {
            //        Console.WriteLine(a[i].ToUpper());
            //    }
            //};
            //sayhi(a);
            //lamda 表达式写法 =>goes to 滚
            ceshi sa = (string[] names) => { for (int i = 0; i < a.Length; i++) { Console.WriteLine(a[i].ToUpper()); } };
            sa(a);
            Console.ReadKey();
        } 
        public static void ProStToUpper(string[] name)
        {
            for (int i = 0; i < name.Length; i++)
            {
                name[i] = name[i].ToUpper();
            }
        }



        public static void ProStrToLower(string[] name)
        {
            for (int i = 0; i < name.Length; i++)
            {
                name[i] = name[i].ToLower();
            }
        }
        public static void ProStrSYH(string[] names)
        {
            for (int i = 0; i < names.Length; i++)
            {
                names[i] = "\"" + names[i] + "\"";
            }
        }
    }
}

  

posted @ 2016-05-23 11:27  尘梦  阅读(346)  评论(0编辑  收藏  举报