码迷,mamicode.com
首页 > 其他好文 > 详细

C#:什么是委托

时间:2014-06-12 18:22:31      阅读:224      评论:0      收藏:0      [点我收藏+]

标签:style   class   blog   code   java   http   

bubuko.com,布布扣
 1 using System;
 2 using System.Collections.Generic;
 3 using System.Linq;
 4 using System.Text;
 5 
 6 namespace myTest
 7 {
 8     class Program
 9     {
10         //定义一个委托类型,它包括0个参数,返回类型为void
11         delegate void DSimpleVoidFunc();
12 
13         static void Main(string[] args)
14         {
15             DSimpleVoidFunc voidF;  //定义DSimpleVoidFunc委托类型变量voidF
16             voidF = PrintHaHa;      //为voidF赋值PrintHaHa函数
17             voidF();               //依次调用委托链中的函数,PrintHaHa
18             voidF += PrintHeHe;     //将PrintHeHe添加到委托链
19             voidF();               //依次调用委托链中的函数,PrintHaHa->PrintHeHe
20             voidF -= PrintHeHe;     //将PrintHeHe从委托链中移除
21             voidF.Invoke();        //依次调用委托链中的函数,PrintHaHa(与voidF()相同)
22         }
23 
24         static void PrintHaHa()
25         {
26             System.Console.WriteLine("HaHa......");
27         }
28 
29         static void PrintHeHe()
30         {
31             System.Console.WriteLine("HeHe......");
32         }
33     }
34 }
bubuko.com,布布扣

 

C#:什么是委托,布布扣,bubuko.com

C#:什么是委托

标签:style   class   blog   code   java   http   

原文地址:http://www.cnblogs.com/hellowzl/p/3781760.html

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