• 委托的几个实例用法


    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);
            }
        }
  • 相关阅读:
    MD5算法MFC实现
    asp.net2.0新特点
    file format
    C专家编程第二章学习笔记
    Bye Czech golden generation
    中间层
    学完谭C之后
    C语言学习之路
    荀子劝学篇
    C语言常用转义字符表
  • 原文地址:https://www.cnblogs.com/chinabc/p/2373066.html
Copyright © 2020-2023  润新知