Which collection type should be used when you need key-value pairs with guaranteed order of insertion?
Answer: D
OrderedDictionary maintains insertion order for key-value pairs. Dictionary<K,V> does not guarantee order in older versions; SortedDictionary sorts by key.
Q.42Medium
What is the time complexity of the IndexOf() method in List<T>?
Answer: C
IndexOf() performs a linear search through the list, resulting in O(n) time complexity in the worst case.
Q.43Easy
Which LINQ method should you use to transform each element of a collection into a new form?
Answer: B
Select() is the LINQ method that projects each element to a new form, similar to map in functional programming languages.
Q.44Medium
What is the primary advantage of using SortedList<K,V> over SortedDictionary<K,V>?
Answer: B
SortedList uses less memory than SortedDictionary but has slower insertion/deletion. SortedDictionary is better for frequent modifications.
Q.45Easy
Which method in Queue<T> allows you to examine the front element without removing it?
Answer: A
Peek() returns the element at the front of the queue without removing it. Dequeue() would remove it.
Advertisement
Q.46Medium
In C# 2024-25, which collection should be used for thread-safe operations without explicit locking?
Answer: B
ConcurrentBag<T> from System.Collections.Concurrent provides thread-safe operations without explicit locking, suitable for multi-threaded scenarios.
Q.47Medium
What happens when you enumerate a Dictionary<K,V> during modification?
Answer: B
Modifying a Dictionary<K,V> while enumerating throws InvalidOperationException. This is a safety feature to prevent undefined behavior.
Q.48Easy
Which collection type uses a hash table internally and provides O(1) average lookup?
Answer: B
HashSet<T> uses a hash table internally, providing O(1) average case lookup, insert, and delete operations.
Q.49Medium
In a scenario with large datasets, which collection should you use to avoid boxing overhead?
Answer: C
List<T> is a generic collection that avoids boxing of value types, whereas ArrayList boxes all values, causing performance overhead.
Q.50Medium
Which method allows you to get an element from a SortedSet<T> at a specific index without using indexer?
Answer: B
ElementAt() is a LINQ method that retrieves an element at a specific index. SortedSet<T> doesn't support direct indexing.
Q.51Hard
In a real-time data processing application, which concurrent collection would be best for producer-consumer pattern?
Answer: B
BlockingCollection<T> supports blocking operations for producer-consumer patterns, allowing threads to wait for items or space.
Q.52Medium
What does TryDequeue() return in ConcurrentQueue<T> when the queue is empty?
Answer: B
TryDequeue() returns false if the queue is empty and sets the out parameter to the default value of T, avoiding exceptions.
Q.53Hard
Which LINQ method combines multiple sequences into a single result with cartesian product?
Answer: B
SelectMany() (also called flatMap in other languages) flattens nested sequences and creates a cartesian product of collections.
Q.54Hard
In a dictionary with 1000 items, what is the expected number of operations for TryGetValue() in C# 2024-25?
Answer: A
TryGetValue() uses hashing for lookup, providing O(1) average case complexity regardless of dictionary size.
Q.55Medium
Which scenario best uses Stack<T> instead of Queue<T> in a practical application?
Answer: B
Stack<T> follows LIFO (Last-In-First-Out) principle, making it ideal for undo/redo functionality where the most recent action is reversed first.
Q.56Easy
What does the Add() method return when adding a duplicate element to a HashSet<T>?
Answer: B
HashSet<T>.Add() returns false if the element already exists, true if added successfully. No exception is thrown.
Q.57Medium
In a scenario where you need to store key-value pairs with fast lookup times, which collection is optimal?
Answer: B
Dictionary<K,V> provides O(1) average-case lookup time using hash tables, making it optimal for key-value pair storage with fast retrieval.
Q.58Medium
Which method should be used to safely check and retrieve a value from a Dictionary<K,V> without throwing an exception?
Answer: B
TryGetValue() is the safe method that returns a boolean indicating success and outputs the value without throwing KeyNotFoundException.
Q.59Medium
What is the primary difference between ArrayList and List<T>?
Answer: B
List<T> is strongly-typed (type-safe) and eliminates boxing/unboxing overhead. ArrayList is non-generic and slower due to boxing of value types.
Q.60Medium
In a multiprocessing environment, which thread-safe collection should be used for concurrent operations?
Answer: B
ConcurrentBag<T> and other Concurrent* collections from System.Collections.Concurrent are thread-safe for multi-threaded scenarios without explicit locking.