xiacy

导航

1.4.1 LINQ 查询表达式和进程内查询

使用查询表达式的前几步:筛选集合

List<Product3> products = Product3.GetSampleProduct();
var filtered = from Product3 p in products
                   where p.Price > 10
                   select p;
foreach (Product3 product in filtered)
       Console.WriteLine(product);

联接(joining)、筛选(filtering)、排序(ordering)和投影(projecting)C# 3.0

List<Product2> product2 = Product2.GetSampleProducts();
List<Product3> product3 = Product3.GetSampleProduct();
var filtered = from p2 in product2
                   join p3 in product3
                   on p2.Name equals p3.Name
                   where p2.Price > 10
                   orderby p2.Name, p3.Name
                   select new { Name = p2.Name, Price = p2.Price };
foreach (var v in filtered)
{
        Console.WriteLine("name={0},price={1}", v.Name, v.Price);
}

 

posted on 2012-04-24 22:49  xiacy  阅读(200)  评论(0编辑  收藏  举报