码迷,mamicode.com
首页 > Windows程序 > 详细

C# 委托的几种写法

时间:2015-11-05 18:20:53      阅读:255      评论:0      收藏:0      [点我收藏+]

标签:

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";
        }
    }

C# 委托的几种写法

标签:

原文地址:http://www.cnblogs.com/wwj1992/p/4940091.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!