Example #1
0
        public void   Show()
        {
            var     list       = new ProductList();
            var     products   = list.GetProductList();
            Product product789 = products.FirstOrDefault(p => p.ProductID == 789);

            Console.WriteLine("Product 789 exists: {0}", product789 != null);
        }
Example #2
0
        /// <summary>
        /// 点标记
        /// </summary>
        public void Show()
        {
            var list     = new ProductList();
            var products = list.GetProductList();

            Console.WriteLine();
            Console.WriteLine("Select_Anonymous_Types_3 点标记");
            //Product Info:p.ProductName, p.Category, Price = p.UnitPrice
            var result = products.Select(t => new { t.ProductName, t.Category, Price = t.UnitPrice });

            Print(result);
        }
Example #3
0
        /// <summary>
        /// 点标记
        /// </summary>
        public void Show()
        {
            var list     = new ProductList();
            var products = list.GetProductList();

            Console.WriteLine();
            Console.WriteLine("OrderByDescending_SImple_2 点标记");
            //First numbers less than 6:
            var result = products.OrderByDescending(x => x.UnitsInStock);

            Print(result);
        }
Example #4
0
        public void Show()
        {
            var     list      = new ProductList();
            var     products  = list.GetProductList();
            Product product12 = (
                from p in products
                where p.ProductID == 12
                select p)
                                .First();

            Console.Write(product12.ProductID);
        }
Example #5
0
        /// <summary>
        /// 点标记
        /// </summary>
        public void Show()
        {
            var list     = new ProductList();
            var products = list.GetProductList();

            Console.WriteLine();
            Console.WriteLine("GroupBy_Simple_3 点标记");
            //n % 5
            var result = products.GroupBy(g => g.Category).Select(g => new { Category = g.Key, products = g });

            Print(result);
        }
Example #6
0
        /// <summary>
        /// 点标记
        /// </summary>
        public void Show()
        {
            var list     = new ProductList();
            var products = list.GetProductList();

            Console.WriteLine();
            Console.WriteLine("Select_Simple2 点标记");
            //Product Names:
            var result = products.Select(t => new { t.ProductID, t.ProductName });

            Print(result);
        }
Example #7
0
        /// <summary>
        /// 点标记
        /// </summary>
        public void Show()
        {
            var list     = new ProductList();
            var products = list.GetProductList();

            Console.WriteLine();
            Console.WriteLine("OrderBy_SImple_3 点标记");
            //p.ProductName
            var result = products.OrderBy(x => x.ProductName).ToList();

            Print(result);
        }
Example #8
0
        /// <summary>
        /// 点标记
        /// </summary>
        public void Show()
        {
            var list     = new ProductList();
            var products = list.GetProductList();

            Console.WriteLine();
            Console.WriteLine("ThenByDescending_SImple 点标记");
            //Sorted digits:
            var result = products.OrderBy(x => x.Category).ThenByDescending(x => x.UnitPrice);

            Print(result);
        }
Example #9
0
        /// <summary>
        /// 点标记
        /// </summary>
        public void Show()
        {
            var list     = new ProductList();
            var products = list.GetProductList();

            Console.WriteLine();
            Console.WriteLine("Distinct_2 点标记");
            //Numbers < 5:
            var result = products.Select(x => x.Category).Distinct();

            Print(result);
        }
Example #10
0
        /// <summary>
        /// 查询表达式
        /// </summary>
        /// <param name="x"></param>
        public void Show(int x)
        {
            var list     = new ProductList();
            var products = list.GetProductList();

            Console.WriteLine();
            Console.WriteLine("Distinct_2 查询表达式");
            //Numbers < 5:
            var result = (from t in products
                          select t.Category).Distinct();

            Print(result);
        }
Example #11
0
        /// <summary>
        /// 查询表达式
        /// </summary>
        /// <param name="x"></param>
        public void Show(int x)
        {
            var list     = new ProductList();
            var products = list.GetProductList();

            Console.WriteLine();
            Console.WriteLine("Select_Simple2 查询表达式");
            //Product Names:
            var result = from t in products
                         select new { t.ProductID, t.ProductName };

            Print(result);
        }
Example #12
0
        /// <summary>
        /// 查询表达式
        /// </summary>
        /// <param name="x"></param>
        public void Show(int x)
        {
            var list     = new ProductList();
            var products = list.GetProductList();

            Console.WriteLine();
            Console.WriteLine("Select_Anonymous_Types_3 查询表达式");
            //Product Info:
            var result = from t in products
                         select new { t.ProductName, t.Category, Price = t.UnitPrice };

            Print(result);
        }
Example #13
0
        /// <summary>
        /// 查询表达式
        /// </summary>
        /// <param name="x"></param>
        public void Show(int x)
        {
            var list     = new ProductList();
            var products = list.GetProductList();

            Console.WriteLine();
            Console.WriteLine("OrderByDescending_SImple_2 查询表达式");
            //First 3 numbers:
            var result = from c in products
                         orderby c.UnitsInStock descending
                         select c;

            Print(result);
        }
Example #14
0
        /// <summary>
        /// 查询表达式
        /// </summary>
        /// <param name="x"></param>
        public void Show(int x)
        {
            var list     = new ProductList();
            var products = list.GetProductList();

            Console.WriteLine();
            Console.WriteLine("OrderBy_SImple_3 查询表达式");
            //First 3 numbers:
            var result = (from c in products
                          orderby c.ProductName
                          select c).ToList();

            Print(result);
        }
Example #15
0
        public void Show()
        {
            var list           = new ProductList();
            var products       = list.GetProductList();
            var categoryCounts =
                from p in products
                group p by p.Category into g
                select new { Category = g.Key, ProductCount = g.Count() };

            foreach (var item in categoryCounts)
            {
                Console.WriteLine(item);
            }
        }
Example #16
0
        /// <summary>
        /// 查询表达式
        /// </summary>
        /// <param name="x"></param>
        public void Show(int x)
        {
            var list     = new ProductList();
            var products = list.GetProductList();

            Console.WriteLine();
            Console.WriteLine("GroupBy_Simple_3 查询表达式");
            //n % 5
            var result = from w in products
                         group w by w.Category into g
                         select new { Category = g.Key, Products = g };

            Print(result);
        }
Example #17
0
        /// <summary>
        /// 查询表达式
        /// </summary>
        /// <param name="x"></param>
        public void Show(int x)
        {
            var list     = new ProductList();
            var products = list.GetProductList();

            Console.WriteLine();
            Console.WriteLine("ThenByDescending_SImple 查询表达式");
            //Sorted digits:
            var result = from c in products
                         orderby c.Category, c.UnitPrice descending
            select c;

            Print(result);
        }
Example #18
0
        /// <summary>
        /// 点标记
        /// </summary>
        public void Show()
        {
            var productList     = new ProductList();
            var soldOutProducts = productList.GetProductList();

            Console.WriteLine();
            Console.WriteLine("Where_Simple3 点标记");
            //In-stock products that cost more than 3.00
            var result = soldOutProducts.Where(t => t.UnitsInStock > 0 && t.UnitPrice > 3.0M);

            foreach (var item in result)
            {
                Console.WriteLine($"{ item.ProductName} is in stock and costs more than 3.00.!");
            }
        }
Example #19
0
        /// <summary>
        /// 点标记
        /// </summary>
        public void Show()
        {
            var productList     = new ProductList();
            var soldOutProducts = productList.GetProductList();

            Console.WriteLine();
            //找出products中UnitsInStock == 0
            Console.WriteLine("Where_Simple2 点标记");
            //找出products中UnitsInStock == 0
            var result = soldOutProducts.Where(t => t.UnitsInStock == 0);

            foreach (var item in result)
            {
                Console.WriteLine($"{ item.ProductName} is sold out!");
            }
        }
Example #20
0
        /// <summary>
        /// 查询表达式
        /// </summary>
        /// <param name="x"></param>
        public void Show(int x)
        {
            var productList     = new ProductList();
            var soldOutProducts = productList.GetProductList();

            Console.WriteLine();
            Console.WriteLine("Where_Simple2 查询表达式");
            //找出products中UnitsInStock == 0
            var result = from t in soldOutProducts
                         where t.UnitsInStock == 0
                         select t;

            foreach (var item in result)
            {
                Console.WriteLine($"{ item.ProductName} is sold out!");
            }
        }
Example #21
0
        /// <summary>
        /// 查询表达式
        /// </summary>
        /// <param name="x"></param>
        public void Show(int x)
        {
            var productList     = new ProductList();
            var soldOutProducts = productList.GetProductList();

            Console.WriteLine();
            Console.WriteLine("Where_Simple3 查询表达式");
            //In-stock products that cost more than 3.00
            var result = from t in soldOutProducts
                         where t.UnitsInStock > 0 &&
                         t.UnitPrice > 3.0M
                         select t;

            foreach (var item in result)
            {
                Console.WriteLine($"{ item.ProductName} is in stock and costs more than 3.00.!");
            }
        }
Example #22
0
        /// <summary>
        /// 点标记
        /// </summary>
        public void Show()
        {
            var list      = new ProductList();
            var products  = list.GetProductList();
            var customers = list.GetCustomerList();

            var productFirstChars =
                from p in products
                select p.ProductName[0];
            var customerFirstChars =
                from c in customers
                select c.CompanyName[0];

            Console.WriteLine();
            Console.WriteLine("Intersect_2 点标记");
            //Numbers < 5:
            var result = productFirstChars.Intersect(customerFirstChars).OrderBy(x => x);

            Print(result);
        }