Oct 28 2024
var fruits = new List<string> { "apple", "banana", "cherry", "date", "elderberry" }; var longFruits = fruits.Where(fruit => fruit.Length > 5); // No execution here foreach (var fruit in longFruits) // Execution happens here { Console.WriteLine(fruit); }
var fruits = new List<string> { "apple", "banana", "cherry", "date", "elderberry" }; var firstFruit = fruits.Where(fruit => fruit.Length > 5).First(); // Execution happens here
var numbers = new List<int> { 1, 2, 3, 4, 5 }; if (numbers.Count() > 0) { // Do something }
var numbers = new List<int> { 1, 2, 3, 4, 5 }; if (numbers.Any()) { // do something }
var customers = db.Customers.Where(c => c.Age > 30); var count = customers.Count(); var first = customers.First(); var last = customers.Last();
var customers = db.Customers.Where(c => c.Age > 30).ToList(); var count = customers.Count; var first = customers[0]; var last = customers[^1];
var validUsers = users.Where(x => x.IsValid).Select(x => x);
var validUsers = users.Where(x => x.IsValid).Select(x => new { x.Id, x.Name });
// Make sure to use IQueryable for database queries to leverage SQL optimizations IQueryable<Product> query = dbContext.Products.Where(p => p.Price > 100);
var query = CompiledQuery.Compile((DataContext db, int age) => db.Customers.Where(c => c.Age == age)); var customers = query(db, 30);
1. Design Patterns that Deliver
This isn’t just another design patterns book. Dive into real-world examples and practical solutions to real problems in real applications.Check out it here.
Go-to resource for understanding the core concepts of design patterns without the overwhelming complexity. In this concise and affordable ebook, I've distilled the essence of design patterns into an easy-to-digest format. It is a Beginner level. Check out it here.
Every Monday morning, I share 1 actionable tip on C#, .NET & Arcitecture topic, that you can use right away.
Join 18,000+ subscribers to improve your .NET Knowledge.
Subscribe to the TheCodeMan.net and be among the 18,000+ subscribers gaining practical tips and resources to enhance your .NET expertise.
Powered by EmailOctopus