using System.Collections.Generic;
public static void Main(string[] args)
StockExchange stockExchange = new StockExchange();
Product cheapest = stockExchange.GetCheapestProduct();
decimal avarage = stockExchange.GetAvaragePrice();
Console.WriteLine("The cheapest product in the list is " + cheapest.Name +
" and is " + (avarage-cheapest.Price).ToString("0.##") + " cheaper than the average price of all the products.");
public long Id { get; set; }
public string Name { get; set; }
public decimal Price { get; set; }
public Product(string name, decimal price)
public class StockExchange
private List<Product> products = new List<Product> {
new Product {Name = "Product 1", Price = 200},
new Product {Name = "Product 2", Price = 50},
new Product {Name = "Product 3", Price = 100},
public Product GetCheapestProduct()
return products.OrderBy(p => p.Price).First();
public decimal GetAvaragePrice()
return (from prod in products select prod.Price).Average();