您的位置:首页 > 编程语言 > C#

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

2015-02-28 09:12 260 查看
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;
}
}
}
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: