zoukankan      html  css  js  c++  java
  • 委托的几个实例用法

    class Program
        {
            private delegate void deleFunc(string str);
            static void Main(string[] args)
            {
                deleFunc func = new Program().Chinese;
                //func("张三");
                func += English;
                func("alex");

                Console.WriteLine( "==================");

                //匿名委托
                deleFunc func1 = delegate(string name)
                                     {
                                         Console.WriteLine("你好,{0}", name);
                                     };
                func1("李四");

                Console.WriteLine("==================");

                //lambda
                deleFunc func2 = (name => { Console.WriteLine("Hello, {0}", name); });
                func2("Jack");

                //action
                Console.WriteLine("==================");
                Action<string> acFun = (m => { Console.WriteLine("您好,{0}", m); });
                acFun("中国人");

                Func<stringstring> funcDelegate = (m => { return string.Format("Hello,{0}", m); });
                string result = funcDelegate("chinese man");
                Console.WriteLine(result);
               

                //实例应用

                int[] i = { 184515681266 };


                Func<intbool> foo = temp_i => temp_i > 10;
                var list = i.Where(foo);
                foreach (int i1 in list)
                {
                    Console.WriteLine(i1);
                }
                Console.WriteLine("==================");

                i.Where(m => m > 15).ToList().ForEach(
                    s => { Console.WriteLine(s); }
                    );


                Console.Read();

            }

            private void Chinese(string name)
            {
                Console.WriteLine("你好:{0}",name);
            }

            private static void English(string name)
            {
                Console.WriteLine("Hello, {0}",name);
            }
        }
  • 相关阅读:
    bat批处理脚本学习系列(一)
    遇到的bug
    util.js 积累的一些基础函数代码
    session过期跳转到登陆页面并解决跳出iframe问题
    Centos7下的rabbitmq-server-3.8.11安装配置
    简单梳理 ES6 函数
    博客目录与学习计划
    DDD中聚合、聚合根的含义以及作用
    DDD中实体与值对象是干什么的
    DDD中限界上下文与通用语言的作用
  • 原文地址:https://www.cnblogs.com/chinabc/p/2373066.html
Copyright © 2011-2022 走看看