Govt. Exams
Entrance Exams
LinkedList<T> provides O(1) AddFirst(), AddLast(), RemoveFirst(), and RemoveLast() operations. List<T> requires O(n) for head removals due to reindexing.
HashSet<T> uses hash-based lookup for Contains(), achieving O(1) average-case time complexity, with O(n) worst-case in case of hash collisions.
SortedDictionary<K,V> uses a red-black tree (binary search tree) for O(log n) operations. SortedSet<T> also uses BST but for single values.
Queue<T> provides FIFO semantics with O(1) Enqueue() and Dequeue() operations. Stack<T> is LIFO, and LinkedList operations vary.
ToList() converts the Dictionary's KeyValuePair<K,V> enumeration into a List<KeyValuePair<K,V>>. ToArray() would create an array instead.
Modifying a collection during enumeration invalidates the enumerator and throws InvalidOperationException. Use a for loop or ToList() to avoid this.
ConcurrentBag<T> and other Concurrent* collections from System.Collections.Concurrent are thread-safe for multi-threaded scenarios without explicit locking.
List<T> is strongly-typed (type-safe) and eliminates boxing/unboxing overhead. ArrayList is non-generic and slower due to boxing of value types.
TryGetValue() is the safe method that returns a boolean indicating success and outputs the value without throwing KeyNotFoundException.
Dictionary<K,V> provides O(1) average-case lookup time using hash tables, making it optimal for key-value pair storage with fast retrieval.