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

  • 相关阅读:
    有关选择的心法(2)
    系统故障排查和确认是否被入侵
    伪善还是妥协
    建恒信安日志审计部署
    有关选择的心法
    数据统治世界----37%原则
    控制二分法
    磁盘空间耗尽导致服务器无法启动
    Linux 标准目录结构 FHS
    Linux入侵类问题排查思路
  • 原文地址:https://www.cnblogs.com/jiangxiaoming/p/12985615.html
Copyright © 2011-2022 走看看