You can use the GroupBy operator and the Average method in LINQ to group a list of products by category and figure out the average price of items in each category.   Here's an example of how you could do this with a LINQ query:  List products = ...
var query = from product in products
group product by product.Category into g
select new { Category = g.Key, AveragePrice = g.Average(p => p.Price) };  In this case, the group clause is used to put the products into groups based on their type. The key to group by is set by the by clause. The Category property of the Product class is the key.   The into clause makes a new variable called g that is an IGroupingstring, Product>, where string is the category and Product is the type of item.   Then, the select clause is used to project the result into a new list of anonymous objects that have the category and the average price of each category.   The query syntax is another way to write this query.  var query = products.GroupBy(p => p.Category)
.Select(g => new { Category = g.Key, AveragePrice = g.Average(p => p.Price) });  In this example, the GroupBy method is called on the list of products and given a lambda expression that specifies the key to group by, which is the Category property of the Product class. Then, the Select operator is used to project the result into a new list of anonymous objects that have the category and the average price of each category.   In both cases, the result will be stored in the query variable. The result is a collection of anonymous objects with the name of the category and the average price of the items in that category.   In short, you can use the GroupBy operator and the Average method in LINQ to group a list of products by category and figure out the average price of items in each category. The group clause is used to group the products by their category. The into clause creates a new variable that is an IGroupingstring, Product>, where string is the category and Product is the type of item. The select clause is then used to project the result into a new sequence of anonymous objects that have the category and the average price of each category.