• 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 }
    
    
  • 相关阅读:
    Struts数据效验
    Struts2中国际化
    ValueStack对象
    Ognl表达式语言
    Struts2拦截器
    ubuntu下tomcat运行不起来解决
    Windows 下的SSH客户端
    远程管理控制ssh
    linux用户和组账户管理
    搭建Java服务器,并且实现远程安全访问linux系统
  • 原文地址:https://www.cnblogs.com/suiyuejinghao123/p/5601984.html
Copyright © 2020-2023  润新知