C# 委托的几种写法

class Program
    {
        delegate string Get(string ss);
        delegate string Get2(int i);
        static Func<string, string> Out = s => s.ToLower();
        static Func<int, string> Out2 = s => { return s.ToString() + "这是Out2"; };
        static void Main(string[] args)
        {
            Get gt = Weituo.Lower;
            Get2 gt2 = Weituo.Upper;
            string test1 = "ABCDEFG";
            int test2 = 123456789;
            Console.WriteLine(gt(test1));
            Console.WriteLine(gt2(test2));
            Console.WriteLine(Out(test1));
            Console.WriteLine(Out2(test2));
            Console.ReadLine();
        }
    }
    public static class Weituo
    {
        public static string Lower(string str)
        {
            return "你输入的大写输出小写字母为:" + str.ToLower();
        }
        public static string Upper(int it)
        {
            return "你出入的数字输出为:" + it + "AAA";
        }
    }

上一篇:100个linux系统常用指令


下一篇:常用 Git 命令清单 转