Grouping by multiple fields using LINQ in C#
Hello everyone! I'm a beginner C# developer and I've encountered a problem when using LINQ. I have a list of `Sale` class objects that contains sales information: store name (`Store`), date (`Date`), and sale amount (`Amount`). I need to group all sales by store and by date (i.e., get the total amount for each store for each day).
Here is my class:
```csharp
public class Sale
{
public string Store { get; set; }
public DateTime Date { get; set; }
public decimal Amount { get; set; }
}
```
And example data:
```csharp
var sales = new List
{
new Sale { Store = "Store A", Date = new DateTime(2023, 1, 1), Amount = 100 },
new Sale { Store = "Store A", Date = new DateTime(2023, 1, 1), Amount = 150 },
n
```
No answers yet.
Log in to leave an answer
Blogs
How to Pass a C++ Interview: Top Questions from A to Z
HTTP Client in Kotlin: Making Requests Properly from A to Z
Java in 2025: What Will Change and Why It's Time to Update Your Code
How to Fix java.lang.UnsupportedClassVersionError: A Complete Guide