私はいくつかのC#3コレクションフィルタのプロトタイプを作成しています。 私は製品のコレクションを持っている:私はフィルタリングするためにLINQを使用する場合、予想通りコレクションをフィルタリングするためにLINQtoObjects上でlambdaを使用する拡張メソッドを使用する場合
public class MyProduct
{
public string Name { get; set; }
public Double Price { get; set; }
public string Description { get; set; }
}
var MyProducts = new List<MyProduct>
{
new MyProduct
{
Name = "Surfboard",
Price = 144.99,
Description = "Most important thing you will ever own."
},
new MyProduct
{
Name = "Leash",
Price = 29.28,
Description = "Keep important things close to you."
}
,
new MyProduct
{
Name = "Sun Screen",
Price = 15.88,
Description = "1000 SPF! Who Could ask for more?"
}
};
は今、それが動作します:
var d = (from mp in MyProducts
where mp.Price < 50d
select mp);
そして、私はフィルタとして働くラムダと組み合わせた場合には拡張メソッドを使用している場合うまく:
var f = MyProducts.Where(mp => mp.Price < 50d).ToList();
質問:違いは何ですか、なぜ他の上のいずれかを使用しますか?