关于lambda语法的困惑

时间:2014-01-02 07:42:19

标签: c# lambda ienumerable

我有一个产品类并存储一些信息,如id,name,price。我想知道如何使用lambda语法获取值,例如大于或小于1000。

这是我的产品类

 namespace ConsoleApplication1
 {
     public class product 
     {
         public double fiyat { get; set; }
         public string ad { get; set; }
         public  int id { get; set; }

         public product(int ids, string ads, double fiyats) 
         {
             id = ids;
             ad = ads;
             fiyat = fiyats;
         }

         public static List<product> getProdcts() 
         {
             List<product> list = new List<product>();
             product[] p = new product[] 
             { 
                 new product(1,"Monitör",1200),
                 new product(2,"Klavye",180),
                 new product(3,"Mouse",75),
                 new product(4,"Laptop",2000),
                 new product(5,"Masa",400)
             };

             list.AddRange(p);
             return list;
         }
     }

     class Program
     {
         static void Main(string[] args)
         {
             List<product> p = product.getProdcts();
             /// IEnumerable<product> queryObj = from item in p where item.Fiyat > 1000   select item;
             IEnumerable<product> quobj =.....
         }
     }
}

1 个答案:

答案 0 :(得分:3)

如果你想使用lambda代替LINQ,你可以通过以下方式实现(无论如何BTW部分是LINQ):

IEnumerable<product> result = p.Where((item) => item.fiyat > 1000);