Home Subjects C# Programming Collections

C# Programming
Collections

C# and .NET for campus placement

15 Q 4 Topics Take Mock Test
Advertisement
Difficulty: All Easy Medium Hard 11–15 of 15
Topics in C# Programming
Q.11 Hard Collections
In a concurrent environment, which collection should be used instead of Dictionary in C# 2024-25?
A Hashtable
B ConcurrentDictionary
C SortedDictionary
D List
Correct Answer:  B. ConcurrentDictionary
EXPLANATION

ConcurrentDictionary<K,V> from System.Collections.Concurrent is thread-safe for multi-threaded applications, unlike Dictionary<K,V>.

Test
Q.12 Hard Collections
What is the difference between ICollection and IEnumerable in terms of capabilities?
A ICollection adds Count and Add/Remove/Clear methods
B Both are identical
C IEnumerable is a collection, ICollection is not
D ICollection cannot iterate, IEnumerable can
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.

Test
Q.13 Hard Collections
Consider: var result = list.OrderByDescending(x => x.Age).ThenBy(x => x.Name); What does this do?
A Sorts by Age ascending then Name descending
B Sorts by Age descending then Name ascending
C Sorts by Name then Age
D Throws a compilation error
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.

Test
Q.14 Hard Collections
What is the space complexity of a HashSet with n elements storing unique values?
A O(n)
B O(log n)
C O(1)
D O(n²)
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.

Test
Q.15 Hard Collections
In C# 2024-25, which LINQ method would you use to find all elements matching a condition in a List?
A FindAll()
B Where()
C Both A and B work
D Filter()
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.

Test
IGET
IGET AI
Online · Exam prep assistant
Hi! 👋 I'm your iget AI assistant.

Ask me anything about exam prep, MCQ solutions, study tips, or strategies! 🎯
UPSC strategy SSC CGL syllabus Improve aptitude NEET Biology tips