Govt. Exams
Entrance Exams
Advertisement
Topics in C# Programming
In a concurrent environment, which collection should be used instead of Dictionary in C# 2024-25?
Correct Answer:
B. ConcurrentDictionary
EXPLANATION
ConcurrentDictionary<K,V> from System.Collections.Concurrent is thread-safe for multi-threaded applications, unlike Dictionary<K,V>.
What is the difference between ICollection and IEnumerable in terms of capabilities?
Correct Answer:
A. ICollection adds Count and Add/Remove/Clear methods
EXPLANATION
IEnumerable<T> only provides iteration. ICollection<T> extends it with Count property and methods like Add(), Remove(), Clear() for modification.
Consider: var result = list.OrderByDescending(x => x.Age).ThenBy(x => x.Name); What does this do?
Correct Answer:
B. Sorts by Age descending then Name ascending
EXPLANATION
OrderByDescending sorts by Age in descending order. ThenBy applies secondary sort by Name in ascending order. This is a multi-level LINQ sort.
What is the space complexity of a HashSet with n elements storing unique values?
Correct Answer:
A. O(n)
EXPLANATION
HashSet<T> requires O(n) space to store n unique elements. Hash tables require linear space proportional to the number of stored elements.
In C# 2024-25, which LINQ method would you use to find all elements matching a condition in a List?
Correct Answer:
C. Both A and B work
EXPLANATION
Both FindAll() and Where() (LINQ) can filter collections. Where() returns IEnumerable and is more modern. FindAll() returns a List directly.