static void Main(string[] args) { const int factor = 10; Func <int, int> squareWithLambda = n => n * n; Console.WriteLine("Square -> " + squareWithLambda(25)); Func <int, int> fact = n => n * factor; Console.WriteLine("Factor -> " + fact(10)); // write the code to return all the books cheaper than $10 Console.WriteLine(); var books = new BookRepo().GetBooks(); //var cheapBooks = books.FindAll(IsCheaperThan10Dollars); var cheapBooks = books.FindAll(b => b.Price < 10); foreach (var book in cheapBooks) { Console.WriteLine(book.Title); } }
private static void Example2() { var books = new BookRepo().GetBooks(); // var cheapBooks = books.FindAll(IsCheaperThan) var cheapBooks = books.FindAll(book => book.Price < 10); foreach (Book book in cheapBooks) { Console.WriteLine(book.Title); } }
static void Main(string[] args) { var books = new BookRepo().GetBooks(); // arg expression out bool var booksUnder10 = books.FindAll(b => b.Price < 10f); // Lamba method used. foreach (var book in booksUnder10) { Console.WriteLine(book.Title); // Returns book3 } }