Home Subjects C# Programming

C# Programming

C# and .NET for campus placement

Practice C# Programming MCQ questions with detailed answers and step-by-step explanations. 290+ free questions available with instant solutions — perfect for competitive exam preparation.
290 Q 4 Topics Take Mock Test
Advertisement
Difficulty: All Easy Medium Hard 1–10 of 290
Topics in C# Programming
Q.1 Hard Collections
In a high-concurrency distributed system, which collection from System.Collections.Concurrent is best for one-to-many relationships?
A ConcurrentDictionary
B ConcurrentBag
C ConcurrentDictionary
D BlockingCollection
Correct Answer:  C. ConcurrentDictionary
EXPLANATION

For one-to-many relationships with concurrent access, combining ConcurrentDictionary with ConcurrentBag (or List) provides thread-safe multi-value storage per key.

Test
Q.2 Medium Collections
In a scenario with frequent additions and removals at both ends, which collection is most efficient?
A List
B LinkedList
C Queue
D Stack
Correct Answer:  B. LinkedList
EXPLANATION

LinkedList<T> provides O(1) AddFirst(), AddLast(), RemoveFirst(), and RemoveLast() operations. List<T> requires O(n) for head removals due to reindexing.

Test
Q.3 Hard Collections
Which collection should be used when you need both indexed access and automatic sorting?
A List
B SortedSet
C SortedList (with integer keys as indices)
D Queue
Correct Answer:  C. SortedList (with integer keys as indices)
EXPLANATION

SortedList<K,V> maintains sorted order by keys and allows O(1) index-based access. SortedSet<T> doesn't support indexing.

Test
Q.4 Medium Collections
What is the time complexity of Contains() method in a HashSet?
A O(n)
B O(log n)
C O(1) average case
D O(n²)
Correct Answer:  C. O(1) average case
EXPLANATION

HashSet<T> uses hash-based lookup for Contains(), achieving O(1) average-case time complexity, with O(n) worst-case in case of hash collisions.

Test
Q.5 Hard Collections
In a real-time cache system with limited memory, which collection supports automatic eviction of least recently used items?
A Dictionary
B MemoryCache from System.Runtime.Caching
C ConcurrentDictionary
D LinkedHashMap
Correct Answer:  B. MemoryCache from System.Runtime.Caching
EXPLANATION

MemoryCache provides LRU-style eviction and memory management policies. Basic collections don't have built-in LRU functionality.

Test
Q.6 Easy Collections
What does the Peek() method do in a Stack?
A Removes and returns the top element
B Returns the top element without removing it
C Returns the bottom element
D Throws an exception if stack is empty
Correct Answer:  B. Returns the top element without removing it
EXPLANATION

Peek() returns the top element without modifying the stack. Pop() removes and returns it. Peek() throws InvalidOperationException if the stack is empty.

Test
Q.7 Medium Collections
Which collection maintains elements in sorted order and is backed by a binary search tree?
A SortedList
B SortedDictionary
C SortedSet
D TreeMap
Correct Answer:  B. SortedDictionary
EXPLANATION

SortedDictionary<K,V> uses a red-black tree (binary search tree) for O(log n) operations. SortedSet<T> also uses BST but for single values.

Test
Q.8 Medium Collections
In a data processing pipeline, if you need FIFO (First-In-First-Out) semantics with O(1) enqueue/dequeue, which collection is best?
A Stack
B LinkedList
C Queue
D SortedList
Correct Answer:  C. Queue
EXPLANATION

Queue<T> provides FIFO semantics with O(1) Enqueue() and Dequeue() operations. Stack<T> is LIFO, and LinkedList operations vary.

Test
Q.9 Easy Collections
What is the space complexity of a HashSet with n elements?
A O(log n)
B O(n)
C O(n²)
D O(1)
Correct Answer:  B. O(n)
EXPLANATION

HashSet<T> requires O(n) space to store n unique elements in the underlying hash table structure.

Test
Q.10 Medium Collections
Which LINQ method is used to convert a Dictionary to a List of key-value pairs?
A ToArray()
B ToList()
C AsEnumerable()
D Cast()
Correct Answer:  B. ToList()
EXPLANATION

ToList() converts the Dictionary's KeyValuePair<K,V> enumeration into a List<KeyValuePair<K,V>>. ToArray() would create an array instead.

Test

About C# Programming Practice on iGET

iGET offers 290+ free C# Programming MCQ questions covering all important topics. Each question is prepared by subject experts and comes with detailed explanations to help you understand concepts deeply, not just memorize answers.

Why prepare with iGET?

100% free access, timed mock tests, instant results with detailed analysis, topic-wise progress tracking, and bookmark feature for revision. Trusted by thousands of aspirants preparing for UPSC, SSC, Bank, Railway, NEET, JEE and other competitive exams across India.

How to use this page effectively

Start by selecting a difficulty level (Easy / Medium / Hard) or pick a specific topic from the topics strip. Attempt questions, check your answer instantly, read the explanation carefully, and bookmark tricky ones for later revision. For full exam-style practice, take a Mock Test from the right sidebar.

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