Python Dynamic Collections: List<T> & Generics
Fixed-size arrays are rigid when user input or data size is unknown. The generic List<T> class (from System.Collections.Generic) is a dynamic resizable array that automatically expands and contracts as you add or remove items.
"If an array is a fixed 6-pack egg carton, a List<T> is a magical accordion shopping cart that expands every time you drop another item into it."
Deep Dive: How It Works
using System.Collections.Generic;: Required namespace.
Declaration: List<string> tasks = new List<string>(); or List<int> scores = new();.
.Add(item): Appends an element to the end of the list.
.Remove(item): Removes the first occurrence of an item.
.RemoveAt(index): Removes item at specific index.
.Count: Returns current number of items (equivalent to array .Length).
.Contains(item): Returns true if item exists in the list.
Syntax Blueprint
using System.Collections.Generic;
List<string> list = new List<string>();
list.Add("First");
list.Add("Second");
Console.WriteLine($"Count: {list.Count}");Dynamic resizable collection with generic type parameter <T>.
Core Rules to Remember



Common Beginner Traps & How to Fix Them
Using .Length instead of .Count on a List<T>Why it happens: Confusion with arrays.
How to fix: Arrays use .Length; Lists and Collections use .Count.
Live Interactive Example
Hit Run Code to see it liveYour Turn: Micro Challenge
No pressure! Edit the starter code below and test your solution with instant feedback.
Build a numbers list
Create a List<int> nums = new List<int>();
Add 50 and 100 with .Add().
Print "List size: 2".
Finished reading and practicing?
Mark this lesson as completed to update your course progress.