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

C#1到C#4使用委托的几种方式

时间:2015-02-28 10:02:06      阅读:131      评论:0      收藏:0      [点我收藏+]

标签:

using System;

namespace DelegateDemo
{
    class Program
    {
        private delegate int Cacu(string str);

        static void Main(string[] args)
        {
            //1
            Cacu cacu = new Cacu(CacuInstance);

            Console.WriteLine(cacu("Hello,Wrold"));

            //2
            Cacu cacu1 = new Cacu(delegate(string str) { return str.Length; });

            Console.WriteLine(cacu1("Hello,Wrold"));

            //3
            Cacu cacu2 = new Cacu((str) => { return str.Length; });

            Console.WriteLine(cacu2("Hello,Wrold"));
        }

        static int CacuInstance(string str)
        {
            return str.Length;
        }
    }
}

 

C#1到C#4使用委托的几种方式

标签:

原文地址:http://www.cnblogs.com/DoNetCoder/p/4304681.html

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