Dec 16 2024
var people = new List<Person> { new Person("Steve", "Jobs"), new Person("Steve", "Carell"), new Person("Elon", "Musk") }; var countByFirstName = people.CountBy(p => p.FirstName); foreach (var entry in countByFirstName) { Console.WriteLine($"There are {entry.Value} people with the name {entry.Key}"); } // Output: // There are 2 people with the name Steve // There are 1 people with the name Elon
var employees = new List<Employee> { new Employee("Alice", "Developer", 70000), new Employee("Bob", "Developer", 80000), new Employee("Charlie", "Manager", 90000), new Employee("Dave", "Manager", 95000) }; var salaryByRole = employees.AggregateBy( emp => emp.Role, seed: 0, (totalSalary, emp) => totalSalary + emp.Salary ); foreach (var entry in salaryByRole) { Console.WriteLine($"Total salary for {entry.Key}: {entry.Value}"); } // Output: // Total salary for Developer: 150000 // Total salary for Manager: 185000
var people = new List<Person> { new Person("Steve", "Jobs"), new Person("Steve", "Carell"), new Person("Elon", "Musk") }; foreach ((var index, var person) in people.Index()) { Console.WriteLine($"Entry {index}: {person.FirstName} {person.LastName}"); } // Output: // Entry 0: Steve Jobs // Entry 1: Steve Carell // Entry 2: Elon Musk
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.