标签:color set font lin public foreach blog 年龄 each
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
namespace λ表达式
{
class VarLinq
{
public void show()
{
//筛选出集合中年龄小于20的
List<User> userList = new List<User>()
{
new User("张三", 21),
new User("李四", 20),
new User("王五", 15),
new User("陆六", 25)
};
//方式一:基于linq
var linqLiset = from u in userList
where u.Age >= 20
select u;
foreach (User u in linqLiset)
{
Console.WriteLine(u);
}
Console.WriteLine("*************************");
//方法二:基于λ表达式
var lambdaList = userList.Where<User>(u => u.Age >= 20);
foreach (User u in lambdaList)
{
Console.WriteLine(u);
}
}
}
}
标签:color set font lin public foreach blog 年龄 each
原文地址:http://www.cnblogs.com/lovling/p/6292695.html