【文件属性】:
文件名称:C#中委托的例子(简单)
文件大小:32KB
文件格式:ZIP
更新时间:2015-01-10 07:58:57
Delegate
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
namespace DelegateDemo
{
public delegate void MyDelegate(string mydelegate); //声明一个delegate对象
public class TestClass
{
//实现有相同参数和返回值的函数
public void HelloDelegate(string mydelegate)
{
Console.WriteLine(mydelegate);
}
//实现有相同参数和返回值的静态函数
public static void HelloStaticDelegate(string mystaticdelegate)
{
Console.WriteLine(mystaticdelegate);
}
}
class Program
{
static void Main(string[] args)
{
TestClass testClass = new TestClass();
MyDelegate mydelegate = new MyDelegate(testClass.HelloDelegate); //产生delegate对象
mydelegate("Hello delegate");
MyDelegate myStaticDelegate = new MyDelegate(TestClass.HelloStaticDelegate);
myStaticDelegate("Hello static delegate");
Console.ReadKey();
}
}
}
【文件预览】:
DelegateDemo
----DelegateDemo()
--------Program.cs(1KB)
--------Properties()
--------DelegateDemo.csproj(2KB)
--------obj()
--------bin()
----DelegateDemo.suo(46KB)
----DelegateDemo.sln(878B)