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());}

  • 相关阅读:
    Makefile学习
    Tmux使用
    Linux进程管理学习资料
    Linux内存管理学习资料
    Python常用的软件包
    Docker 学习
    Intel处理器技术文档
    Firefly-RK3399笔记
    Linux Kernel API
    ARM 技术文档
  • 原文地址:https://www.cnblogs.com/jiangxiaoming/p/12985615.html
Copyright © 2011-2022 走看看