예제 #1
0
        static void LambdaExpressions()
        {
            var lambdaExamples = new LambdaExamples();

            var books          = new LambdaExpressions.Book();
            var bookRepository = new LambdaExpressions.BookRepository().GetBooks();

            var cheapBooks = bookRepository.FindAll(books.IsCheaperThanTenDollars);

            foreach (var book in cheapBooks)
            {
                Console.WriteLine(book.Title);
            }

            // This Lambda Expression is exactly the same as the above code
            var cheapBooksLambda = bookRepository.FindAll(book => book.Price < 10);

            foreach (var book in cheapBooksLambda)
            {
                Console.WriteLine(book.Title);
            }
        }
예제 #2
0
 //static int Square(int number)
 //{
 //    return number * number;
 //}
 //predicate method
 static bool IsCheaperThan10Dollars(Book book)
 {
     return book.Price < 10;
 }
예제 #3
0
 //predicate condition:
 static bool IsCheaperThan50Dollar(Book book)
 {
     return(book.Price < 50);
 }