C# - Collection Classes Questions and Answers

Practice Mode
Showing 10 of 39 questions
Q31
Which collection class is thread-safe by default
  • A List
  • B ArrayList
  • C Explanation: Hashtable is thread-safe by default.
  • D Dictionary
Answer: Option C
Explanation: Hashtable is thread-safe by default.
Q32
Which property returns the number of elements in a collection
  • A Length
  • B Size
  • C Explanation: Count property gives the total number of elements.
  • D Total
Answer: Option C
Explanation: Count property gives the total number of elements.
Q33
Which collection is best suited for frequent insertions and deletions
  • A Array
  • B List
  • C Explanation: LinkedList is efficient for frequent insert and delete operations.
  • D Stack
Answer: Option C
Explanation: LinkedList is efficient for frequent insert and delete operations.
Q34
Which method removes all elements from a collection
  • A RemoveAll()
  • B Delete()
  • C Explanation: Clear() removes all elements from the collection.
  • D Reset()
Answer: Option C
Explanation: Clear() removes all elements from the collection.
Q35
Which collection stores data in unordered key-value pairs
  • A SortedList
  • B Explanation: Dictionary does not maintain sorted order by default.
  • C Stack
  • D Queue
Answer: Option B
Explanation: Dictionary does not maintain sorted order by default.
Q36
Which collection can store different data types together
  • A List<T>
  • B Dictionary<T,K>
  • C Explanation: ArrayList can store different data types as objects.
  • D LinkedList<T>
Answer: Option C
Explanation: ArrayList can store different data types as objects.
Q37
Which method checks whether a key exists in Dictionary
  • A Exists()
  • B HasKey()
  • C Explanation: ContainsKey() checks for the existence of a key.
  • D FindKey()
Answer: Option C
Explanation: ContainsKey() checks for the existence of a key.
Q38
Which collection is recommended over ArrayList for better performance
  • A Queue
  • B Stack
  • C Explanation: List<T> avoids boxing and unboxing, improving performance.
  • D Hashtable
Answer: Option C
Explanation: List<T> avoids boxing and unboxing, improving performance.
Q39
Which collection is used to represent a fixed-size collection
  • A List
  • B Explanation: Array has a fixed size once created.
  • C Dictionary
  • D LinkedList
Answer: Option B
Explanation: Array has a fixed size once created.
Questions and Answers for Competitive Exams Various Entrance Test