Collections — data structures for storing and managing data.
List<T>:
1var list = new List<int> { 1, 2, 3 };2list.Add(4); // O(1) amortized3list.Remove(1); // O(n)4list.Contains(2); // O(n)
Dictionary<TKey, TValue>:
1var dict = new Dictionary<string, int>();2dict["one"] = 1; // O(1)3dict.TryGetValue("one", out var val); // O(1)4dict.Remove("one"); // O(1)
HashSet<T>:
1var set = new HashSet<int> { 1, 2, 3 };2set.Add(1); // false (already exists)3set.Contains(1); // O(1)
Queue<T>:
1var queue = new Queue<string>();2queue.Enqueue("first"); // O(1)3queue.Dequeue(); // O(1)4queue.Peek(); // O(1)
Stack<T>:
1var stack = new Stack<string>();2stack.Push("first"); // O(1)3stack.Pop(); // O(1)4stack.Peek(); // O(1)