标签:
Where:
IEnumerable<Users> user = list.Where(delegate(Users d) { return d.Age > 1; });
foreach (Users users in user)
{
Console.WriteLine(users.Name + ";" + users.Age);
}
Foreach:
list.ForEach(new Action<Users>(delegate(Users user) { Console.WriteLine(user.Name + ";" + user.Age); }));
FindAll:
list.FindAll(new Predicate<Users>(delegate(Users user) { return user.Age > 1; }));
//使用FindAll可以帮助我们根据条件 筛选出一个新的集合
list.FindAll(delegate(Users user) { return user.Age > 1; });
Sort:
list.Sort(delegate(Users users1, Users users2)
{
return users2.Age - users1.Age;
});
Select:
//使用select方法 遍历list集合,并转换一个匿名对象的集合
var li = list.Select(delegate(Users users)
{
return new { Age = users.Age, Date = DateTime.Now };
});
C# List where FindAll ForEach Comparsion Select
标签:
原文地址:http://www.cnblogs.com/mylanyangyang/p/5795854.html