6.20 委托

 1 using System;
 2 using System.Collections.Generic;
 3 using System.Linq;
 4 using System.Text;
 5 
 6 namespace 委托
 7 {
 8     public delegate int aa(int a,int b);
 9     class Program
10     {
11         static void Main(string[] args)
12         {
13             /*fangfa bb = new fangfa();
14               aa cc = bb.jiafa;*/  //原始写法
15             aa cc = new fangfa().jiafa;//简化写法
16             //方法必须与委托结构一样才可以委托,例如此处二者都是int类型
17             //加法
18             int a = cc(5, 6);
19             Console.WriteLine(a);
20             //减法
21            aa dd = new fangfa().jianfa;
22             a = dd(5, 6);
23             Console.WriteLine(a);
24 
25              //混合运算
26             a = cc(5, 4) - dd(5, 4);
27             Console.WriteLine(a);
28 
29 
30             Console.ReadLine();
31             //委托:获取动作执行函数,例如获取点击鼠标的动作,执行一个函数
32             //委托就是代理,点击事件是一种特殊的委托,特殊在可以接收用户的动作
33 
34         }
35 
36     }
37 }
 1 using System;
 2 using System.Collections.Generic;
 3 using System.Linq;
 4 using System.Text;
 5 
 6 namespace 委托
 7 {
 8     class fangfa
 9     {
10         public int jiafa(int a, int b)
11         {
12             return a + b;
13         }
14         public int jianfa(int a, int b)
15         {
16             return a - b;
17         }
18     }
19 }

 

posted @ 2016-06-20 22:00  一人饮酒醉(SeVen❤)  阅读(130)  评论(0编辑  收藏  举报