我有一个如下列表:
var products = new List<Product>
{
new Product { Id = 1, Category = "Electronics", Value = 15.0 },
new Product { Id = 2, Category = "Groceries", Value = 40.0 },
new Product { Id = 3, Category = "Garden", Value = 210.3 },
new Product { Id = 4, Category = "Pets", Value = 2.1 },
new Product { Id = 5, Category = "Electronics", Value = 19.95 },
new Product { Id = 6, Category = "Pets", Value = 5.50 },
new Product { Id = 7, Category = "Electronics", Value = 250.0 },
};
我想按类别分组并获得属于该类别的“值”的总和。示例:电子产品:284.95
虽然我可以通过其他方式做到这一点,但我想学习查找的用法。
是否可以在查找中获得这两个值(类别和值)?如果是,我该怎么做?