zoukankan      html  css  js  c++  java
  • Func<T,TResult>代理

    .NET平台已经发生了很多变化,最近决定好好的系统的学习一下了,开发做了这么多年,老实说很多时候都是在吃老本,这样下去不行的。。。

    今天学习的是Func<T,TResult>,它是新的委托申明方式,较之前的简洁多了。

    using System;
    using System.Collections.Generic;
    using System.Linq;
    using System.Text;
    
    namespace BaiduTranslate
    {
        class LambdaTest
        {
            delegate int InterDelegate(int a);
            /// <summary>
            /// 传统方法
            /// </summary>
            public void Tradition()
            {
                InterDelegate idelegate = AA;
                idelegate += BB;
                idelegate(10);
            }
            /// <summary>
            /// 新方法
            /// </summary>
            public void New()
            {
                Func<int, int> idelegate = AA;
                idelegate += BB;
                idelegate(10);
            }
            /// <summary>
            /// 遍历执行注册列表
            /// </summary>
            public void Test()
            {
                Tradition();
                Console.WriteLine("-------------分割线-----------");
                New();
            }
    
            private int AA(int c)
            {
                Console.WriteLine("AA method:{0}", c);
                return c;
            }
    
            private int BB(int c)
            {
                Console.WriteLine("BB method:{0}", c);
                return c;
            }
        }
    }

    运行结果是一样一样的。

  • 相关阅读:
    「Poetize7」Freda的访客
    「Poetize8」Divisible
    「Poetize5」Vani和Cl2捉迷藏
    1082. 员工的重要度
    1080. 最大的岛
    1079. 连续子串计数(经典)
    1078. 数组的度
    1071. 词典中最长的单词
    1068. 寻找数组的中心索引
    1062. 洪水填充(经典)
  • 原文地址:https://www.cnblogs.com/yyq745201/p/4648221.html
Copyright © 2011-2022 走看看