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); } }
//static int Square(int number) //{ // return number * number; //} //predicate method static bool IsCheaperThan10Dollars(Book book) { return book.Price < 10; }
//predicate condition: static bool IsCheaperThan50Dollar(Book book) { return(book.Price < 50); }