Home Subjects C# Programming Collections

C# Programming
Collections

C# and .NET for campus placement

38 Q 4 Topics Take Mock Test
Advertisement
Difficulty: All Easy Medium Hard 11–20 of 38
Topics in C# Programming
Q.11 Medium Collections
Which scenario best uses Stack instead of Queue in a practical application?
A Processing network packets
B Undo/Redo functionality in editors
C Job scheduling
D Task queuing
Correct Answer:  B. Undo/Redo functionality in editors
EXPLANATION

Stack<T> follows LIFO (Last-In-First-Out) principle, making it ideal for undo/redo functionality where the most recent action is reversed first.

Test
Q.12 Medium Collections
What does TryDequeue() return in ConcurrentQueue when the queue is empty?
A null
B false and sets output parameter to default
C Throws exception
D Returns empty value
Correct Answer:  B. false and sets output parameter to default
EXPLANATION

TryDequeue() returns false if the queue is empty and sets the out parameter to the default value of T, avoiding exceptions.

Test
Q.13 Medium Collections
Which method allows you to get an element from a SortedSet at a specific index without using indexer?
A GetAt()
B ElementAt()
C Get()
D Retrieve()
Correct Answer:  B. ElementAt()
EXPLANATION

ElementAt() is a LINQ method that retrieves an element at a specific index. SortedSet<T> doesn't support direct indexing.

Test
Q.14 Medium Collections
In a scenario with large datasets, which collection should you use to avoid boxing overhead?
A ArrayList
B Hashtable
C List
D SortedList
Correct Answer:  C. List
EXPLANATION

List<T> is a generic collection that avoids boxing of value types, whereas ArrayList boxes all values, causing performance overhead.

Test
Q.15 Medium Collections
What happens when you enumerate a Dictionary during modification?
A It skips modified elements
B It throws InvalidOperationException
C It includes modified elements
D It pauses enumeration automatically
Correct Answer:  B. It throws InvalidOperationException
EXPLANATION

Modifying a Dictionary<K,V> while enumerating throws InvalidOperationException. This is a safety feature to prevent undefined behavior.

Test
Q.16 Medium Collections
In C# 2024-25, which collection should be used for thread-safe operations without explicit locking?
A List
B ConcurrentBag
C Dictionary
D ArrayList
Correct Answer:  B. ConcurrentBag
EXPLANATION

ConcurrentBag<T> from System.Collections.Concurrent provides thread-safe operations without explicit locking, suitable for multi-threaded scenarios.

Test
Q.17 Medium Collections
What is the primary advantage of using SortedList over SortedDictionary?
A Faster insertion and deletion
B Better memory efficiency for small collections
C Supports null keys
D Thread-safe operations
Correct Answer:  B. Better memory efficiency for small collections
EXPLANATION

SortedList uses less memory than SortedDictionary but has slower insertion/deletion. SortedDictionary is better for frequent modifications.

Test
Q.18 Medium Collections
What is the time complexity of the IndexOf() method in List?
A O(1)
B O(log n)
C O(n)
D O(n log n)
Correct Answer:  C. O(n)
EXPLANATION

IndexOf() performs a linear search through the list, resulting in O(n) time complexity in the worst case.

Test
Q.19 Medium Collections
Which collection type should be used when you need key-value pairs with guaranteed order of insertion?
A Hashtable
B Dictionary
C SortedDictionary
D OrderedDictionary
Correct Answer:  D. OrderedDictionary
EXPLANATION

OrderedDictionary maintains insertion order for key-value pairs. Dictionary<K,V> does not guarantee order in older versions; SortedDictionary sorts by key.

Test
Q.20 Medium Collections
Which collection in C# maintains insertion order and allows fast removal from both ends?
A Deque
B LinkedList
C Queue
D SortedSet
Correct Answer:  B. LinkedList
EXPLANATION

LinkedList<T> allows O(1) removal from both ends and maintains insertion order. Deque<T> is not a standard C# collection.

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