using System; using System.Collections.Generic; using System.Diagnostics; using System.Linq; using automatically_implemented_properties; namespace automatically_implemented_properties { class Program { static void Main(string[] args) { Product[] products = { new Product {Name = "Kayak", Category = "Watersports", Price = 275M}, new Product {Name = "Lifejacket", Category = "Watersports", Price = 48.95M}, new Product {Name = "Soccer ball", Category = "Soccer", Price = 19.50M}, new Product {Name = "Corner flag", Category = "Soccer", Price = 34.95M} }; var results = from product in products orderby product.Price descending select new { product.Name, product.Price }; int count = 0; // print out the names foreach (var p in results) { Console.WriteLine("Item: {0}, Cost: {1}", p.Name, p.Price); if (++count == 3) { break; } } } } public static class MyExtensionMethod { public static decimal TotalPrices(this IEnumerable productEnum) { decimal total = 0; foreach (Product prod in productEnum) { total += prod.Price; } return total; } public static IEnumerable FilterByCategory(this IEnumerable productEnum, string categoryParam) { foreach (Product prod in productEnum) { if (prod.Category == categoryParam) { yield return prod; } } } public static IEnumerable Filter(this IEnumerable productEnum, Func selectorParam) { foreach (Product prod in productEnum) { if (selectorParam(prod)) { yield return prod; } } } } }