C#中使用委托的3种方式代码示例
时间:2022-03-05 09:50:42|栏目:.NET代码|点击: 次
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#部署数据库及IIS站点
栏 目:.NET代码
下一篇:WCF基础介绍并创建简单应用程序
本文标题:C#中使用委托的3种方式代码示例
本文地址:http://www.codeinn.net/misctech/195255.html






