zoukankan      html  css  js  c++  java
  • 委托

    using System;
    using System.Collections.Generic;
    using System.Linq;
    using System.Text;
    using System.Threading.Tasks;
    
    namespace 委托练习
    {
        //定义委托
        public delegate void AddDelegate(int a, int b);
        class Class1
        {
           
            static void Main(string[] args)
            {
                // 创建委托实例
                int a = 3, b = 4;
                AddDelegate add = new AddDelegate(Add);
                add(a, b);
    
                Console.ReadKey();
            }
            //把相关参数传给方法
            public static void Add(int a, int b)
            {
                Console.WriteLine(a + b);
            }
    
        }
    }

    using System;
    using System.Collections.Generic;
    using System.Linq;
    using System.Text;
    using System.Threading.Tasks;

    namespace 委托练习
    {
    public class 无聊练练
    {
    static void Main(string[] args)
    {
    //写一个Action这个泛型集合(say是下面的静态方法)
    Action<string> test = new Action<string>(say);
    //调用函数
    test("这个是下面的Str");
    Console.ReadKey();
    }
    //定义这个静态方法,方便上面的调用,感觉这个就像是一样的,果然有共同性
    public static void say(string str)
    {
    Console.WriteLine(str);
    }
    }
    }

  • 相关阅读:
    ArrayList和Vector的比较
    ExtJs与jQuery的比较
    列表类型的内建函数
    序列类型函数
    SQL函数
    HTTP状态码
    序列切片
    数值运算
    数值类型转换
    Python中is和==的区别
  • 原文地址:https://www.cnblogs.com/yaodengfeng/p/7753859.html
Copyright © 2011-2022 走看看