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);
            }
        }
  • 相关阅读:
    Apache 性能配置优化
    大数据企业备份
    Docker限制容器可用的CPU
    docker运行容器后agetty进程cpu占用率100%
    Ubuntu下crontab命令的用法
    set -x与set +x指令
    CentOS设置程序开机自启动的方法
    maven 打JAR包资源文件指定路径与文件读取
    hadoop-maven项目打包成可执行的jar
    如何将maven项目打包成可执行的jar
  • 原文地址:https://www.cnblogs.com/chinabc/p/2373066.html
Copyright © 2011-2022 走看看