Search⌘ K
AI Features

Solution: Food Delivery Revenue Analysis

Explore how to analyze food delivery revenue using LINQ in C#. Learn to group orders by restaurant, calculate total revenues, and display results efficiently using collection manipulation and projection techniques.

We'll cover the following...
C# 14.0
using FoodDelivery;
var dailyOrders = new List<Order>
{
new Order { RestaurantName = "Burger Joint", Item = "Cheeseburger", OrderTotal = 12.50m },
new Order { RestaurantName = "Pizza Palace", Item = "Pepperoni Pizza", OrderTotal = 22.00m },
new Order { RestaurantName = "Burger Joint", Item = "Fries and Shake", OrderTotal = 8.75m },
new Order { RestaurantName = "Sushi Central", Item = "Spicy Tuna Roll", OrderTotal = 15.00m },
new Order { RestaurantName = "Pizza Palace", Item = "Garlic Bread", OrderTotal = 5.50m },
new Order { RestaurantName = "Sushi Central", Item = "Sashimi Platter", OrderTotal = 35.00m }
};
var revenueReport = dailyOrders
.GroupBy(o => o.RestaurantName)
.Select(group => new
{
Name = group.Key,
TotalRevenue = group.Sum(o => o.OrderTotal)
});
Console.WriteLine("Daily Revenue Report:");
foreach (var report in revenueReport)
{
Console.WriteLine($" - {report.Name}: ${report.TotalRevenue}");
}
...