Could C# Linq do combinatorics?

前端 未结 3 1221
死守一世寂寞
死守一世寂寞 2021-01-29 16:28

I have this data structure:

class Product
{
    public string Name { get; set; }
    public int Count { get; set; }
}

var list = new List(){ { Na         


        
3条回答
  •  太阳男子
    2021-01-29 16:54

    You need the Count extension method

    list.Count(p => p.Count <= 100);
    

    EDIT:

    If you want the sum of the items, Where and Sum extension methods could be utilized:

    list.Where(p => p.Count <= 100).Sum(p => p.Count);
    

提交回复
热议问题