C# LOOPS & ARRAYSChapter 2 · C# Loops & Arrays
Dynamic generic lists
The List<T> class from System.Collections.Generic represents a strongly-typed list of objects. Unlike arrays, a list grows dynamically as elements are added.
Worked example
using System;
using System.Collections.Generic;
class Program {
static void Main() {
List<string> stars = new List<string>();
stars.Add("Sirius");
stars.Add("Vega");
Console.WriteLine(stars.Count); // 2
stars.Remove("Vega");
}
}How it reads
- List<string> defines a list containing strings
- stars.Add(...) appends a string to the end of the list
- stars.Count returns the current number of elements

Cloud tip: The <T> syntax is a generic. You specify the type of elements inside the angle brackets, ensuring type safety.


