C# 几行代码理解Delegate
![](https://images.cnblogs.com/OutliningIndicators/ContractedBlock.gif)
1 using System;
2 using System.Collections.Generic;
3 using System.Linq;
4 using System.Text;
5
6 namespace ConsoleApplication2
7 {
8 delegate string Deg(string Canshu);//申明一个delegate 这个委托可以用来"执行" 参数为string返回值也为string的方法
9 class Program
10 {
11 static void Main(string[] args)
12 {
13 Deg deg = new Deg(TestDeg); //实例化一个delegate ,将这个委托指向方法TestDeg
14 Console.WriteLine(deg("sss"));//执行代理,背后其实就是执行TestDeg
15 Console.Read();
16 }
17 public static string TestDeg(string s) {
18 return s;
19 }
20 }
21
22
23 }
24
posted on 2010-05-07 13:26 Master zhu 阅读(133) 评论(0) 编辑 收藏 举报