예제 #1
0
 public static string TextIt(this ProductClass p)
 {
     return(p.Name
            + " Which comes in quantities of "
            + p.Quantity
            + " has a unit price of "
            + p.UnitPrice);
 }
예제 #2
0
        static void Main(string[] args)
        {
            ProductClass[] prods = CreateProducts();

            //----------------------------------------------------
            ProductClass beer = Array.Find(prods, FindBeer);

            Console.WriteLine(beer.TextIt());

            ProductClass beer1 = Array.Find(prods,
                                            delegate(ProductClass p)
            {
                return(p.Name == "Beer");
            });

            Console.WriteLine(beer1.TextIt());

            ProductClass beer2 = Array.Find(prods,
                                            p =>
            {
                return(p.Name == "Beer");
            });

            Console.WriteLine(beer2.TextIt());

            ProductClass beer3 = Array.Find(prods, p => p.Name == "Beer");

            Console.WriteLine(beer3.TextIt());
            //-----------------------------------------------------

            var prodsFiltered = prods.Where(p =>
            {
                string temp = p.Name.ToLower();
                return(temp.StartsWith("z"));
            });

            foreach (ProductClass p in prodsFiltered)
            {
                Console.WriteLine(p.TextIt());
            }

            //-------------------------------------------------

            Action <int> printNumber = x => Console.WriteLine(x);

            printNumber(23);

            Program.printNumber(22);
        }
예제 #3
0
 private static ProductClass[] CreateProducts()
 {
     ProductClass[] prods = new ProductClass[]
     {
         new ProductClass {
             Name = "Displayport Adapter", Quantity = 1, UnitPrice = 25.50m
         },
         new ProductClass {
             Name = "Beer", Quantity = 12, UnitPrice = 10.99m
         },
         new ProductClass {
             Name = "Z-Wave USB Controller", Quantity = 1, UnitPrice = 49.99m
         },
         new ProductClass {
             Name = "ZigBee Plugwise Starter Kit", Quantity = 1, UnitPrice = 209.00m
         },
     };
     return(prods);
 }
예제 #4
0
 static bool FindBeer(ProductClass p)
 {
     return(p.Name == "Beer");
 }