In enterprise programming, data is rarely a single value; itโs usually a stream of thousands of records. Module 3 teaches you how to store, search, and manipulate groups of objects efficiently. Choosing the wrong collection can make your application slow (high latency), while the right one ensures high performance.
The fundamental difference lies in memory flexibility.
string[]): * Fixed Size: You must declare the size at the start (e.g., new string[5]). To add a 6th item, you have to create a brand new array and copy everything over.
List<T>): * Dynamic Size: They grow and shrink automatically as you add or remove items.
.Add(), .Remove(), .Sort(), and .Clear().These are the “Big Four” data structures you will use 90% of the time in C#.
<T>The most commonly used collection. Itโs an ordered list of items accessible by index.
<TKey, TValue>Stores data in Key-Value pairs. Think of a real dictionary: the “Word” is the Key, and the “Definition” is the Value.
UserId, a Dictionary finds them almost instantly, whereas a List would have to check every single item.<T> (LIFO)Last-In, First-Out. Imagine a stack of physical plates. The last plate you put on top is the first one you take off.
<T> (FIFO)First-In, First-Out. Imagine a line at a coffee shop. The first person in line is the first one served.
In early versions of .NET, we used “ArrayLists” which could hold anything (integers, strings, and dogs all in one list). This was dangerous and slow.
Generics (represented by the <T> symbol) allow you to define a collection with a “Type Parameter.”
List<int> will refuse to accept a string. This catches errors at compile-time rather than crashing the app at runtime.Sometimes, a standard List isn’t enough. You might want a collection that automatically logs every time an item is added, or one that only allows unique values.
To create a custom collection, you usually:
Collection<T> or IEnumerable<T>.InsertItem or RemoveItem to add your custom business logic.ReadOnlyEmployeeCollection that prevents any external code from modifying the company’s payroll list.In professional software, we talk about Time Complexity.
By the end of this module, you stop asking “How do I store this?” and start asking “How will I access this?”