In C# 2024-25, which LINQ method would you use to find all elements matching a condition in a List<T>?
Answer: C
Both FindAll() and Where() (LINQ) can filter collections. Where() returns IEnumerable and is more modern. FindAll() returns a List directly.
Q.2Hard
What is the space complexity of a HashSet<T> with n elements storing unique values?
Answer: A
HashSet<T> requires O(n) space to store n unique elements. Hash tables require linear space proportional to the number of stored elements.
Q.3Hard
Consider: var result = list.OrderByDescending(x => x.Age).ThenBy(x => x.Name); What does this do?
Answer: B
OrderByDescending sorts by Age in descending order. ThenBy applies secondary sort by Name in ascending order. This is a multi-level LINQ sort.
Q.4Hard
What is the difference between ICollection<T> and IEnumerable<T> in terms of capabilities?
Answer: A
IEnumerable<T> only provides iteration. ICollection<T> extends it with Count property and methods like Add(), Remove(), Clear() for modification.
Q.5Hard
In a concurrent environment, which collection should be used instead of Dictionary<K,V> in C# 2024-25?
Answer: B
ConcurrentDictionary<K,V> from System.Collections.Concurrent is thread-safe for multi-threaded applications, unlike Dictionary<K,V>.
Advertisement
Q.6Hard
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.7Hard
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.8Hard
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.9Hard
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.10Hard
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.11Hard
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.12Hard
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.13Hard
In a real-time cache system with limited memory, which collection supports automatic eviction of least recently used items?
Answer: B
MemoryCache provides LRU-style eviction and memory management policies. Basic collections don't have built-in LRU functionality.
Q.14Hard
Which collection should be used when you need both indexed access and automatic sorting?
Answer: C
SortedList<K,V> maintains sorted order by keys and allows O(1) index-based access. SortedSet<T> doesn't support indexing.
Q.15Hard
In a high-concurrency distributed system, which collection from System.Collections.Concurrent is best for one-to-many relationships?
Answer: C
For one-to-many relationships with concurrent access, combining ConcurrentDictionary with ConcurrentBag (or List) provides thread-safe multi-value storage per key.