Back to list

LINQ - Data Query Operations

Lv.5871@mukitaro13 playsDec 31, 2025

LINQ queries for data analysis with grouping, aggregation, and projection operations.

preview.csharp
C#
1public class DataAnalyzer
2{
3 public IEnumerable<CustomerSummary> GetTopCustomers(List<Order> orders, int count)
4 {
5 return orders
6 .Where(o => o.Status == OrderStatus.Completed)
7 .GroupBy(o => o.CustomerId)
8 .Select(g => new CustomerSummary
9 {
10 CustomerId = g.Key,
11 TotalOrders = g.Count(),
12 TotalSpent = g.Sum(o => o.Total),
13 AverageOrderValue = g.Average(o => o.Total)
14 })
15 .OrderByDescending(c => c.TotalSpent)
16 .Take(count);
17 }
18
19 public Dictionary<string, decimal> GetSalesByCategory(List<Product> products)
20 {
21 return products
22 .GroupBy(p => p.Category)
23 .ToDictionary(
24 g => g.Key,
25 g => g.Sum(p => p.Price * p.QuantitySold)
26 );
27 }
28}

Custom problems are not included in rankings