Lamda ForEach使用

List<User> list = new List<User>()
            {
                new User{id=1 },
                new User{id=2 },
                new User{id=3 },
            };
            
            list.ForEach(p => Console.WriteLine(p.id));//等同于forearth
           //里面写判断
            list.ForEach(p =>
           {
               if (p.id==2)
               {
                   Console.WriteLine(p.id.ToString());
               }
           }            
            );
 public class User
    {
        public int id { get; set; }
        public string name { get; set; }
        public int parentId { get; set; }
    }
原文地址:https://www.cnblogs.com/macT/p/11771654.html