using System.Collections.Generic;
static void Main(string[] args)
var cities = new List<City>
Products = new List<Product>
new Product { Name = "Milk", Price = 2.5m },
new Product { Name = "Bread", Price = 1.5m }
Products = new List<Product>
new Product { Name = "Milk", Price = 3.0m },
new Product { Name = "Cheese", Price = 4.5m }
Products = new List<Product>
new Product { Name = "Milk", Price = 2.0m },
new Product { Name = "Bread", Price = 1.0m }
Products = new List<Product>
new Product { Name = "Milk", Price = 2.5m },
new Product { Name = "Cheese", Price = 4.0m }
var cheapestCityForMilk = cities
AveragePrice = c.Shops.SelectMany(s => s.Products)
.Where(p => p.Name == "Milk")
.OrderBy(c => c.AveragePrice)
Console.WriteLine($"The city where the average price of \"Milk\" is the lowest is {cheapestCityForMilk.City} with an average price of {cheapestCityForMilk.AveragePrice}.");
public string Name { get; set; }
public List<Shop> Shops { get; set; }
public string Name { get; set; }
public List<Product> Products { get; set; }
public string Name { get; set; }
public decimal Price { get; set; }