Govt. Exams
Entrance Exams
SortedDictionary<K,V> automatically maintains keys in sorted order. Dictionary<K,V> maintains insertion order but not sorted order.
Dictionary enforces unique keys. Attempting to add a duplicate key throws ArgumentException. Use dict["a"] = 2 to update.
Push() adds an element to the stack, while Pop() removes and returns the top element. If stack is empty, Pop throws InvalidOperationException.
IEnumerable interface provides GetEnumerator() method, enabling foreach iteration. IEnumerable<T> is the generic version.
Accessing an invalid index throws IndexOutOfRangeException. This is a runtime error that must be caught to prevent program crashes.
Dictionary<K,V> in .NET maintains insertion order (in recent versions) and provides O(1) lookup. SortedDictionary maintains sorted order instead.
List<T> is backed by an array, allowing direct index-based access in constant time O(1).
Clear() removes all elements from a collection. Remove() removes a specific element, and RemoveAt() removes an element at a specific index.