C#introdotnet

Collections essentials

The three workhorse collections — a growable list, a keyed dictionary, and a uniqueness-enforcing set — plus the collection-expression syntax that builds them all the same way.

List<T> grows on demand, Dictionary<K,V> maps keys to values with TryGetValue, and HashSet<T> keeps only distinct items — and [ ... ] collection expressions initialise any of them.

Build a list and iterate it

C#intro
0ms
Count: 3First: apple- apple- banana- cherry
Reference · output compiled offline, not runnable in-browser

Count reports 3 after the three Add calls and fruits[0] is apple, confirming a List<T> preserves insertion order so positional indexing and foreach both walk the items in the order added.