class Program
{
#region LINQ语句结合Lambda表达式使用
var pgrm = new Programer[] {
new Programer { Name="张三", Language="C#", Position="Leader"},
new Programer { Name="李四", Language="C#", Position="Coder"},
new Programer { Name="王五", Language="Java", Position="PM"}
};
var query = from p in pgrm
where p.Language == "C#" && p.Name.StartsWith("张")
select new { Name = p.Name, Position = p.Position };
foreach (var p in query)
{
Console.WriteLine("Name:{0}\t\tPosition:{1}", p.Name, p.Position);
}
// 扩展方法 lambda表达式演示
var table = pgrm.Where(
p => p.Position == "PM" || p.Language == "Java"
);
table.ToList().ForEach(e => Console.WriteLine(e.Name)); // "=>" 接匿名方法 {}
#endregion
}
class Programer
{
public string Name { get; set; }
public string Language { get; set; }
public string Position { get; set; }
}
LINQ语句结合Lambda表达式使用
最新推荐文章于 2019-07-09 17:09:23 发布