Arrays & Lists
Arrays — Fixed-Size Containers
An array is like a row of lockers. You decide how many lockers you want when you build it, and each locker gets a number starting from 0 (not 1 — computers are weird like that). You can put one thing in each locker and grab it back by its number.
The catch? Once you build the row, you can't add or remove lockers. The size is locked in — this is what computer scientists call a static array.
Array Basics
List<T> — The Flexible Array
Arrays are fast but rigid. List<T> is a dynamic array — like a magical expanding backpack — you can keep adding items and it grows automatically. You can also remove items, insert at specific positions, and search easily.
The <T> part means you tell the list what type it holds: List<int>, List<string>, etc. This is called a generic — it's type-safe, meaning you can't accidentally put a string in a list of ints.
In real-world C#, you'll use List<T> way more often than arrays.
List<T> in Action
LINQ — Query Your Data Like a Boss
LINQ (Language Integrated Query) lets you filter, transform, and search collections with clean, readable code. Think of it as having a super-powered search engine built right into C#.
Two key methods to start with:
.Where()— filter: "give me only the items that match this rule".Select()— transform: "change each item into something else"
We'll dive deeper into LINQ in a later lesson, but here's a taste.
LINQ Basics with Collections
Quick check
Continue reading