C# - Collection Classes Questions and Answers
C# Collection Classes questions with answers are highly useful for mastering data storage and manipulation techniques in programming. Topics like Lists, Dictionaries, Queues, and HashSets are frequently tested in programming interviews and coding assessments. Practicing programming questions and answers with explanations helps students improve their understanding of C# data structures and performance optimization. Such programming MCQs and problem-based aptitude questions are commonly asked in technical interviews and placement tests conducted by companies like Microsoft, TCS, and Infosys. Strengthen your skills through C# programming test practice and learn to use collections efficiently.
Questions on data collections in C language. Broaden skills with arrays and pointers
C# - Collection Classes
31. Which collection class is thread-safe by default
- List
- ArrayList
- Explanation: Hashtable is thread-safe by default.
- Dictionary
32. Which property returns the number of elements in a collection
- Length
- Size
- Explanation: Count property gives the total number of elements.
- Total
33. Which collection is best suited for frequent insertions and deletions
- Array
- List
- Explanation: LinkedList is efficient for frequent insert and delete operations.
- Stack
34. Which method removes all elements from a collection
- RemoveAll()
- Delete()
- Explanation: Clear() removes all elements from the collection.
- Reset()
35. Which collection stores data in unordered key-value pairs
- SortedList
- Explanation: Dictionary does not maintain sorted order by default.
- Stack
- Queue
36. Which collection can store different data types together
- List<T>
- Dictionary<T,K>
- Explanation: ArrayList can store different data types as objects.
- LinkedList<T>
37. Which method checks whether a key exists in Dictionary
- Exists()
- HasKey()
- Explanation: ContainsKey() checks for the existence of a key.
- FindKey()
38. Which collection is recommended over ArrayList for better performance
- Queue
- Stack
- Explanation: List<T> avoids boxing and unboxing, improving performance.
- Hashtable
39. Which collection is used to represent a fixed-size collection
- List
- Explanation: Array has a fixed size once created.
- Dictionary
- LinkedList