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 1–10 of 18
Topics in C# Programming
Q.1 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.2 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.3 Easy Collections
What does the Add() method return when adding a duplicate element to a HashSet?
A true
B false
C throws an exception
D returns the index
Correct Answer:  B. false
EXPLANATION

HashSet<T>.Add() returns false if the element already exists, true if added successfully. No exception is thrown.

Test
Q.4 Easy Collections
Which collection type uses a hash table internally and provides O(1) average lookup?
A TreeSet
B HashSet
C SortedSet
D LinkedHashSet
Correct Answer:  B. HashSet
EXPLANATION

HashSet<T> uses a hash table internally, providing O(1) average case lookup, insert, and delete operations.

Test
Q.5 Easy Collections
Which method in Queue allows you to examine the front element without removing it?
A Peek()
B Front()
C Top()
D View()
Correct Answer:  A. Peek()
EXPLANATION

Peek() returns the element at the front of the queue without removing it. Dequeue() would remove it.

Test
Q.6 Easy Collections
Which LINQ method should you use to transform each element of a collection into a new form?
A Transform()
B Select()
C Map()
D Convert()
Correct Answer:  B. Select()
EXPLANATION

Select() is the LINQ method that projects each element to a new form, similar to map in functional programming languages.

Test
Q.7 Easy Collections
In a HashSet, what happens when you try to add a duplicate element?
A Throws InvalidOperationException
B Returns false and element is not added
C Replaces the existing element
D Adds the element creating duplicates
Correct Answer:  B. Returns false and element is not added
EXPLANATION

HashSet<T>.Add() returns false if the element already exists and does not add duplicates, maintaining set semantics.

Test
Q.8 Easy Collections
Which IEnumerable method should be used to filter elements based on a condition and maintain type safety?
A Where
B Select
C Filter
D Find
Correct Answer:  A. Where
EXPLANATION

Where<T> is a LINQ method that filters elements based on a predicate condition while maintaining type safety in the collection.

Test
Q.9 Easy Collections
Which method in Stack returns the top element without removing it?
A Pop()
B Peek()
C Top()
D Get()
Correct Answer:  B. Peek()
EXPLANATION

Peek() returns the top element without removal. Pop() removes it. Top() and Get() are not Stack<T> methods.

Test
Q.10 Easy Collections
What is the time complexity of accessing an element by index in List?
A O(n)
B O(log n)
C O(1)
D O(n log n)
Correct Answer:  C. O(1)
EXPLANATION

List<T> is backed by an array, allowing O(1) random access by index.

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