Mastering Collections and LINQ

Intermediate Updated March 21, 2025

🔄 Mastering Collections and LINQ

🔸 List vs Dictionary vs HashSet

List<int> nums = new List<int> { 1, 2, 3 };
Dictionary<string, int> ages = new Dictionary<string, int>
{
    { "Alice", 30 },
    { "Bob", 25 }
};
HashSet<string> tags = new HashSet<string> { "csharp", "intermediate" };

### 🔸 Introduction to LINQ

```csharp
int[] numbers = { 1, 2, 3, 4, 5, 6 };
var evens = numbers.Where(n => n % 2 == 0).ToList();

var squares = numbers.Select(n => n * n);

### 🔸 Advanced LINQ Techniques

```csharp
var groupByLength = words.GroupBy(w => w.Length);

var topScores = students
    .OrderByDescending(s => s.Score)
    .Take(3)
    .Select(s => s.Name);