Unique list of items using LINQ

后端 未结 6 1410
星月不相逢
星月不相逢 2021-02-01 05:39

I\'ve been using LINQ for a while now, but seem to be stuck on something with regards to Unique items, I have the folling list:

List stock = new Lis         


        
6条回答
  •  深忆病人
    2021-02-01 05:46

    Sounds like it's a simple Where clause needed.

    List kitchen= stock.Where(s=>s.Type=="Kitchen Appliance")
                              .OrderBy(s=>s.Description).ToList();
    

    If you wanted strictly the Types contained in the source list:

    string[] typesFound = stock.Select(s=>s.Type).Distinct().ToArray();

提交回复
热议问题