Home Subjects C# Programming Collections

C# Programming
Collections

C# and .NET for campus placement

18 Q 4 Topics Take Mock Test
Advertisement
Difficulty: All Easy Medium Hard 11–18 of 18
Topics in C# Programming
Q.11 Easy Collections
Which collection throws an exception when you try to dequeue from an empty Queue?
A Dequeue()
B Peek()
C TryDequeue()
D Remove()
Correct Answer:  A. Dequeue()
EXPLANATION

Dequeue() throws InvalidOperationException on empty queue. TryDequeue() returns false instead. Peek() also throws but doesn't remove.

Test
Q.12 Easy Collections
Which collection in C# maintains insertion order and allows duplicate elements?
A List
B HashSet
C SortedSet
D Queue
Correct Answer:  A. List
EXPLANATION

List<T> maintains insertion order and allows duplicates. HashSet<T> doesn't allow duplicates, SortedSet<T> sorts elements, and Queue<T> follows FIFO.

Test
Q.13 Easy Collections
What will be the output of the following code?
List nums = new List {1, 2, 3};
nums.Add(4);
Console.WriteLine(nums.Count);
A 3
B 4
C 5
D 1
Correct Answer:  B. 4
EXPLANATION

The list initially has 3 elements. After Add(4), it has 4 elements. Count returns 4.

Test
Q.14 Easy Collections
Which collection in C# implements LIFO (Last In First Out) principle?
A Queue
B Stack
C List
D LinkedList
Correct Answer:  B. Stack
EXPLANATION

Stack<T> follows LIFO where the last element added is the first to be removed. Queue<T> follows FIFO (First In First Out).

Test
Q.15 Easy Collections
What does the Count property of a collection return in C#?
A The maximum capacity of the collection
B The current number of elements in the collection
C The index of the last element
D The memory allocated to the collection
Correct Answer:  B. The current number of elements in the collection
EXPLANATION

Count returns the number of elements currently stored. Capacity is different and refers to allocated space.

Test
Q.16 Easy Collections
Which collection allows duplicate keys in C#?
A Dictionary
B Hashtable
C List
D SortedDictionary
Correct Answer:  C. List
EXPLANATION

List<T> allows duplicates as it stores elements sequentially. Dictionary and Hashtable enforce unique keys; attempting to add a duplicate key throws an exception.

Test
Q.17 Easy Collections
What is the main difference between ArrayList and List in C#?
A ArrayList is generic, List is not
B List is type-safe and faster, ArrayList is not type-safe
C ArrayList has better performance than List
D List can only store reference types
Correct Answer:  B. List is type-safe and faster, ArrayList is not type-safe
EXPLANATION

List<T> is generic and type-safe, preventing boxing/unboxing overhead and providing compile-time type checking. ArrayList stores objects and requires casting.

Test
Q.18 Easy Collections
Which namespace in C# contains the collections like List, Dictionary, and Queue?
A System.Collections.Generic
B System.Collections.Specialized
C System.Data.Collections
D System.Linq.Collections
Correct Answer:  A. System.Collections.Generic
EXPLANATION

System.Collections.Generic is the standard namespace for generic collections in C#. It provides type-safe collections that prevent runtime errors.

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