Govt. Exams
Entrance Exams
Dequeue() throws InvalidOperationException on empty queue. TryDequeue() returns false instead. Peek() also throws but doesn't remove.
List<T> maintains insertion order and allows duplicates. HashSet<T> doesn't allow duplicates, SortedSet<T> sorts elements, and Queue<T> follows FIFO.
List nums = new List {1, 2, 3};
nums.Add(4);
Console.WriteLine(nums.Count);
The list initially has 3 elements. After Add(4), it has 4 elements. Count returns 4.
Stack<T> follows LIFO where the last element added is the first to be removed. Queue<T> follows FIFO (First In First Out).
Count returns the number of elements currently stored. Capacity is different and refers to allocated space.
List<T> allows duplicates as it stores elements sequentially. Dictionary and Hashtable enforce unique keys; attempting to add a duplicate key throws an exception.
List<T> is generic and type-safe, preventing boxing/unboxing overhead and providing compile-time type checking. ArrayList stores objects and requires casting.
System.Collections.Generic is the standard namespace for generic collections in C#. It provides type-safe collections that prevent runtime errors.