using System.Collections.Generic;
public static void Main()
var products = GetProducts();
var orders = GetOrders();
var allProducts = from p in products
var allProductsExt = products.Select(p => p);
var idAndNameOnly = from p in products
select new { p.Id, p.Name };
var idAndNameOnlyExt = products.Select(p => new { p.Id, p.Name });
var lowStock = from p in products
var lowStockExt = products.Where(p => p.StockLevel < 5);
var byPrice = from p in products
orderby p.Price descending
var byPriceExt = products.OrderByDescending(p => p.Price);
var orderProducts = from o in orders
Products = from p in products
var orderProductsExt = orders.Select(o => new { Order = o, Products = products.Where(p => o.ProductIds.Contains(p.Id))});
var distinctPrices = (from p in products
select p.Price).Distinct();
var distinctPricesExt = products.Select(p => p.Price).Distinct();
var top3Expensive = (from p in products
orderby p.Price descending
var top3ExpensiveExt = products.OrderByDescending(p => p.Price).Take(3);
var priceSum = products.Sum(p => p.Price);
var productCount = products.Count();
var minStockLevel = products.Min(p => p.StockLevel);
foreach(var p in top3Expensive)
Console.WriteLine(p.Id + " " + p.Name);
public static IList<Product> GetProducts()
var products = new List<Product>();
Description = "Succulent pork sausages, from the finest farms in the land",
Description = "Delicious bacon, fry it or grill it!",
Name = "Chicken Fillets",
Description = "Our chickens are treated well, and our fillets will treat you well",
Description = "If you love fish and you love cakes then you'll love our fish cakes",
Description = "Lovely with mint sauce",
public static IList<Order> GetOrders()
var orders = new List<Order>();
ProductIds = new List<int>(){ 1, 4 }
ProductIds = new List<int>(){ 2, 3, 5 }
ProductIds = new List<int>(){ 3, 1 }
ProductIds = new List<int>(){ 4 }
ProductIds = new List<int>(){ 2, 4, 3, 1 }
public int Id {get; set;}
public string Name {get; set;}
public string Description {get; set;}
public decimal Price {get; set;}
public int StockLevel {get; set;}
public int Id {get; set;}
public IList<int> ProductIds {get; set;}