zoukankan      html  css  js  c++  java
  • 委托的定义

    委托的解释:可以赋值一个方法的引用,通过委托变量来调用这个方法

    委托的定义方法:delegate 方法签名(T)    ps:方法的签名=返回值+方法名+参数

                                 委托声明的变量只能指向相同返回值和相同的参数类型。

    private delegate string GetAString();
    
    static void Main(){
    	int x = 40;
    	GetAString firstStringMethod = new GetAString(x.ToString);//第一种赋值方式(初始化)
    GetAString firstStringMethod =x.ToString //第二种赋值方式(初始化)
    String s=
    firstStringMethod();//第一种调用方式
    String s=firstStringMethod.Invoke//第二种调用方式
    Console.WriteLine(s); }

      内置的Action委托

           无返回值有参数Action<T> T的最大个数为16为多种类型

           内置Func委托

          可有返回值和参数 Func<T1,T2> 前面的T1代表参数类型最多为16个,后面的T2为返回值类型。

    private delegate string GetAString();
    static void Main(){int x = 40;GetAString firstStringMethod = new GetAString(x.ToString);Console.WriteLine(firstStringMethod());}

  • 相关阅读:
    mybatis
    Spring原理
    JS 之继承
    HTTP协议简介2
    JS 之原型,实例,构造函数之间的关系
    HTTP协议简介1
    freemarker语法简介
    CSS 动画之十-图片+图片信息展示
    JS实现颜色值的转换
    抓包工具charles的使用
  • 原文地址:https://www.cnblogs.com/jiangxiaoming/p/12985615.html
Copyright © 2011-2022 走看看