Exemplo n.º 1
0
        static void Main(string[] args)
        {
            var books    = BooksRepository.GetBooks();
            var selbooks = (from b in books
                            where b.Price > 500
                            orderby b.Price descending
                            select new { Title = b.Title, Price = b.Price * 1.18 }
                            ).Take(3);

            foreach (var book in selbooks)
            {
                Console.WriteLine("{0} {1}", book.Title, book.Price);
            }


            var onebook = (from b in books
                           where b.Id == 100
                           select b
                           ).FirstOrDefault();

            if (onebook != null)
            {
                Console.WriteLine(onebook.Title);
            }
        }
Exemplo n.º 2
0
        static void Main(string[] args)
        {
            var books    = BooksRepository.GetBooks();
            var selbooks = books.Where(b => b.Price > 400)
                           .OrderByDescending(b => b.Price)
                           .Select(b => new { Title = b.Title, Price = b.Price * 1.18 })
                           .Skip(2)
                           .Take(2);

            //foreach (var book in selbooks)
            //    Console.WriteLine("{0} {1}", book.Title, book.Price);


            var maxprice = books.Max(b => b.Price);

            var costlybooks = books.Where(b => b.Price == maxprice);


            //foreach (var book in costlybooks)
            //    Console.WriteLine("{0} {1}", book.Title, book.Price);

            var mybooks = books.Where(IsCostlyBook).Take(2);

            //foreach (var book in mybooks)
            //    Console.WriteLine("\n{0} {1}\n", book.Title, book.Price);


            var allbooks = books.Where(IsCostlyBook).ToList();


            var onebook = books.Where(b => b.Id == 100).FirstOrDefault();

            if (onebook != null)
            {
                Console.WriteLine(onebook.Title);
            }
        }