Which collection throws an exception when you try to dequeue from an empty Queue<T>?
Answer: A
Dequeue() throws InvalidOperationException on empty queue. TryDequeue() returns false instead. Peek() also throws but doesn't remove.
Q.22Easy
What is the time complexity of accessing an element by index in List<T>?
Answer: C
List<T> is backed by an array, allowing O(1) random access by index.
Q.23Medium
Which collection type is best suited for implementing a priority queue in C#?
Answer: B
PriorityQueue<T, TPriority> was introduced in .NET 6 specifically for priority queue implementation.
Q.24Medium
What happens when you add a duplicate key to a Dictionary<TKey, TValue>?
Answer: B
Dictionary<TKey, TValue> throws ArgumentException when adding duplicate keys. Use indexer notation to update values.
Q.25Medium
Which LINQ method returns the first element matching a condition, or throws if none exists?
Answer: A
First() throws InvalidOperationException if no match. FirstOrDefault() returns null/default. Find() is a List<T> method.
Advertisement
Q.26Medium
What is the primary difference between SortedList<TKey, TValue> and SortedDictionary<TKey, TValue>?
Answer: A
SortedList uses arrays (faster retrieval, slower insertion). SortedDictionary uses red-black tree (balanced insertion/deletion). SortedDictionary has better insertion time O(log n) vs O(n) for SortedList.
Q.27Medium
Which collection in C# is NOT thread-safe by default?
Answer: C
List<T> is not thread-safe. All Concurrent* collections (ConcurrentDictionary, ConcurrentBag, ConcurrentQueue) are thread-safe.
Q.28Medium
What does the Contains() method use in HashSet<T> to determine membership?
Answer: C
HashSet<T> uses hash codes for O(1) average lookup. It computes hash code first, then uses equality comparison.
Q.29Medium
Which of the following collections preserves insertion order and is thread-safe?
Answer: B
ConcurrentDictionary is thread-safe. While it doesn't strictly preserve insertion order like some collections, it's the thread-safe option among these choices.
Q.30Medium
What is the time complexity for removing an element from the middle of a LinkedList<T>?
Answer: A
If you have a LinkedListNode<T>, removal is O(1). However, finding the node is O(n), so overall search + remove is O(n).
Q.31Easy
Which method in Stack<T> returns the top element without removing it?
Answer: B
Peek() returns the top element without removal. Pop() removes it. Top() and Get() are not Stack<T> methods.
Q.32Medium
In C# 2024-25, which collection should be used for fast membership testing with no duplicates?
Answer: B
HashSet<T> provides O(1) average lookup and prevents duplicates. SortedSet maintains order but slower. List<T> requires O(n) lookup.
Q.33Medium
What is the output of the following code?
var dict = new Dictionary<int, string>();
dict[1] = "A";
dict[1] = "B";
Console.WriteLine(dict[1]);
Answer: B
Using the indexer on Dictionary with an existing key updates the value, not throws. Output is 'B'.
Q.34Hard
Which collection type allows you to iterate in reverse order efficiently?
Answer: B
LinkedList<T> has Reverse enumerator for efficient reverse iteration. Others don't have built-in reverse iteration support.
Q.35Hard
What happens when you call Clear() on a Dictionary<TKey, TValue>?
Answer: B
Clear() removes all elements but doesn't deallocate capacity. The dictionary remains usable with count=0.
Q.36Hard
Which LINQ method should you use to get distinct elements from a List<int> while maintaining performance?
Answer: B
Distinct() is the standard LINQ method for removing duplicates. While HashSet works, Distinct() is more idiomatic.
Q.37Hard
In a competitive exam scenario, if you need both fast lookup and sorted iteration, which should you choose?
Answer: B
SortedDictionary provides O(log n) lookup and maintains sorted order during iteration. Alternatives are slower or require post-processing.
Q.38Medium
Which collection in C# maintains insertion order and allows fast removal from both ends?
Answer: B
LinkedList<T> allows O(1) removal from both ends and maintains insertion order. Deque<T> is not a standard C# collection.
Q.39Easy
Which IEnumerable method should be used to filter elements based on a condition and maintain type safety?
Answer: A
Where<T> is a LINQ method that filters elements based on a predicate condition while maintaining type safety in the collection.
Q.40Easy
In a HashSet<T>, what happens when you try to add a duplicate element?
Answer: B
HashSet<T>.Add() returns false if the element already exists and does not add duplicates, maintaining set semantics.