मैं कुछ सी # 3 संग्रह फिल्टर प्रोटोटाइप कर रहा हूं और इस पर आया हूं।
मेरे पास उत्पादों का संग्रह है:
public class MyProduct
{
public string Name { get; set; }
public Double Price { get; set; }
public string Description { get; set; }
}
var MyProducts = new List
{
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?"
}
};
अब अगर मैं फ़िल्टर करने के लिए LINQ का उपयोग करता हूं तो यह अपेक्षित कार्य करता है:
var d = (from mp in MyProducts
where mp.Price < 50d
select mp);
और यदि मैं लैम्ब्डा के साथ संयुक्त एक्सटेंशन विधि का उपयोग करता हूं तो फ़िल्टर भी काम करता है:
var f = MyProducts.Where(mp => mp.Price < 50d).ToList();
Question: What is the difference, and why use one over the other?