//c# 2 public static void QueryVersionTwo() { List <ProductVersionTwo> products = ProductVersionTwo.GetSomeProduct(); Predicate <ProductVersionTwo> test = delegate(ProductVersionTwo p) { return(p.Price > 10m); }; List <ProductVersionTwo> matches = products.FindAll(test); Action <ProductVersionTwo> print = Console.WriteLine; matches.ForEach(print); }
public static void TestClassFeatures() { ArrayList product1 = ProductVersionOne.GetSomeProduct(); product1.Sort(new ProductComparerVersionOne()); foreach (var t in product1) { Console.WriteLine(t); } //generic no boxing List <ProductVersionTwo> product2 = ProductVersionTwo.GetSomeProduct(); //product2.Sort(new ProductComparerVersionTwo()); product2.Sort(delegate(ProductVersionTwo x, ProductVersionTwo y) { return(x.Name.CompareTo(y.Name)); }); foreach (var item in product2) { Console.WriteLine(item); } var product3 = ProductVersionThree.GetSomeProduct(); //delegate version1 product3.Sort(delegate(ProductVersionThree x, ProductVersionThree y) { return(x.Name.CompareTo(y.Name)); }); product3.Sort((x, y) => x.Name.CompareTo(y.Name)); foreach (var p in product3) { Console.WriteLine(p); } var product4 = ProductVersionFour.GetSomeProduct(); foreach (var p in product4.OrderBy(p => p.Name)) { Console.WriteLine(p); } foreach (var p in product4) { Console.WriteLine(p); } }