static void ReverseEverything(ProductInfo[] products) { Console.WriteLine("=> Products in reverse"); var allProducts = products.Reverse(); foreach (var prod in allProducts) { Console.WriteLine(prod); } Console.WriteLine(); }
static void SelectProductNames(ProductInfo[] products) { Console.WriteLine("=> All Names:"); var allNames = from p in products select p.Name; foreach (var p in allNames) { Console.WriteLine(p); } Console.WriteLine(); }
static void GetNamesAndDescriptions(ProductInfo[] products) { Console.WriteLine("=> GetNamesAndDescriptions:"); var nameDesc = from p in products select new { p.Name, p.Description }; foreach (var p in nameDesc) { Console.WriteLine(p); } Console.WriteLine(); }
static void SelectEverything(ProductInfo[] products) { Console.WriteLine("=> All producrt details:"); var allProducts = from p in products select p; foreach (var p in allProducts) { Console.WriteLine(p); } Console.WriteLine(); }
static void AlphabetizeProductNames( ProductInfo[] products ) { // Get names of products, alphabetized. var subset = from p in products orderby p.Name select p; Console.WriteLine("Ordered by Name:"); foreach (var p in subset) { Console.WriteLine(p.ToString()); } }
static void GetOverstock(ProductInfo[] products) { Console.WriteLine("=> GetOverstock"); var overstock = from p in products where p.NumberInStock > 25 where p.NumberInStock > 25 //works fine select p; foreach (var p in overstock) { Console.WriteLine(p); } Console.WriteLine(); }
static void GetNamesAndDescriptions(ProductInfo[] products) { Console.WriteLine("Names and Descriptions:"); var nameDesc = from p in products select new {p.Name, p.Description}; foreach (var items in nameDesc) Console.WriteLine(items.ToString()); }
static void GetOverstock(ProductInfo[] products) { Console.WriteLine("The overstock items!"); var overstock = from p in products where p.NumberInStock > 25 select p; foreach (ProductInfo c in overstock) Console.WriteLine(c.ToString()); }
static void ListProductNames(ProductInfo[] products) { Console.WriteLine("Only product names:"); var names = from p in products select p.Name; foreach (var n in names) Console.WriteLine("Name: {0}", n); }
static void SelectEverything(ProductInfo[] products) { Console.WriteLine("All product details:"); var allProducts = from p in products select p; foreach (var prod in allProducts) Console.WriteLine(prod.ToString()); }
static Array GetProjectedSubset( ProductInfo[] products ) { var nameDesc = from p in products select new { p.Name, p.Description }; return nameDesc.ToArray(); }
static void GetNamesAndDescriptions( ProductInfo[] products ) { Console.WriteLine("Names and Descriptions:"); var nameDesc = from p in products select new { p.Name, p.Description }; foreach (var item in nameDesc) { // Could also use Name and Description properties directly. Console.WriteLine(item.ToString()); } }
static Array GetProjectedSubset(ProductInfo[] products) { var nameDesc = from p in products select new { p.Name, p.Description }; // Mape set of anonymous objects to an Array object. return nameDesc.ToArray(); }
static void AlphabetizeProductNames(ProductInfo[] products) { Console.WriteLine("=> Ordered by Name"); var subset = from p in products orderby p.Name select p; foreach (var p in subset) { Console.WriteLine(p); } Console.WriteLine(); }
static void ReverseEverything(ProductInfo[] products) { Console.WriteLine("Product in reverse:"); var allProducts = from p in products select p; foreach (var prod in allProducts.Reverse()) Console.WriteLine(prod.ToString()); }
static void AlphabetizeProductNames(ProductInfo[] products) { var subset = from p in products orderby p.Name descending select new {p.Name}; Console.WriteLine("Ordered by Name:"); foreach (var p in subset) Console.WriteLine(p.ToString()); }
static void GetOverstock( ProductInfo[] products ) { Console.WriteLine("The overstock items!"); // Get only the items where we have more than // 25 in stock. var overstock = from p in products where p.NumberInStock > 25 select p; foreach (ProductInfo c in overstock) { Console.WriteLine(c.ToString()); } }