• lambda 复习用


      //筛选
    List<Person> persons = PersonsList(); persons = persons.Where(p => p.Age > 6).ToList(); //所有Age>6的Person的集合 persons = persons.Where(p => p.Name.Contains("儿子")).ToList(); //所有Name包含儿子的Person的集合
     //委托  逛超市
            delegate int GuangChaoshi(int a);
            static void Main(string[] args)
            {          
               // GuangChaoshi gwl = JieZhang;
                GuangChaoshi gwl = p => p + 10;
                Console.WriteLine(gwl(10) + "");   //打印20,表达式的应用
                Console.ReadKey();
            }      
     //委托  逛超市 带参数
            delegate int GuangChaoshi(int a,int b);
            static void Main(string[] args)
            {            
                GuangChaoshi gwl = (p,z) => z-(p + 10);
                Console.WriteLine(gwl(10,100) + "");   //打印80,z对应参数b,p对应参数a
                Console.ReadKey();
            }
     //Func<T>委托
    static void Main(string[] args)
            {
                Func<int, string> gwl = p => p + 10 + "--返回类型为string";            
                Console.WriteLine(gwl(10) + "");   //打印‘20--返回类型为string’,z对应参数b,p对应参数a
                Console.ReadKey();
            }
     //Func<T>委托
    static void Main(string[] args)
            {
                Func<int, int, bool> gwl = (p, j) =>
                    {
                        if (p + j == 10)
                        {
                            return true;
                        }
                        return false;
                    };
                Console.WriteLine(gwl(5,5) + "");   //打印‘True’,z对应参数b,p对应参数a
                Console.ReadKey();
            }
    //Action委托
    public class Test  
    {  
        static public Action A;  
        static public Action<int> B;  
        static public Action<int, string> C;  
        static public Action<int, string, int> D;  
        static public Action<int, string, int, string> E;  
      
        static void Main()  
        {  
            A = () =>  
                {  
                    Console.WriteLine("I'm A ");  
                };  
      
            B = (i) =>  
                {  
                    Console.WriteLine("I'm B " + i);  
                };  
      
            C = (i, s) =>  
                {  
                    Console.WriteLine("I'm C " + i + " " + s) ;  
                } ;  
      
            D = (i, s, j) =>  
                {  
                    Console.WriteLine("I'm D " + i + " " + s + " " + j) ;  
                } ;  
      
            E = (i, s, j, t) =>  
                {  
                    Console.WriteLine("I'm E " + i + " " + s + " " + j + " " + t);  
                };  
      
            A();  
            B(1);  
            C(1, "a");  
            D(1, "a", 2);  
            E(1, "a", 2, "b");  
                     
            Console.ReadKey();  
  • 相关阅读:
    swift网络数据请求方法
    使用jQuery在javascript中自定义事件
    javascript循环事件只响应最后一次的问题处理
    关于PHP 时区错误的问题
    安装MySql出现Error Nr.1045的解决办法
    view的阴影效果shadowColor
    关于Swift中的泛函数find的问题
    [BZOJ3196][Tyvj1730]二逼平衡树
    [BZOJ4671]异或图
    [BZOJ4621]Tc605
  • 原文地址:https://www.cnblogs.com/KQNLL/p/5212435.html
Copyright © 2020-2023  润新知