Home Subjects C# Programming

C# Programming

C# and .NET for campus placement

76 Q 4 Topics Take Mock Test
Advertisement
Difficulty: All Easy Medium Hard 11–20 of 76
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
Q.19 Easy OOP in C#
Consider a payment processing system where PaymentProcessor is an abstract class with an abstract method ProcessPayment(). CreditCardProcessor and UPIProcessor are derived classes. What will happen if you try to instantiate PaymentProcessor directly in C#?
A It will compile successfully and create an instance with default implementations
B Compiler error - cannot instantiate an abstract class
C Runtime error - abstract class cannot be instantiated at runtime
D It will compile but throw an error only if ProcessPayment() is called
Correct Answer:  B. Compiler error - cannot instantiate an abstract class
EXPLANATION

Abstract classes in C# cannot be instantiated directly. The compiler enforces this rule at compile-time. Abstract classes serve as blueprints and must be inherited by concrete classes that provide implementations for all abstract members. This ensures proper design and forces derived classes to implement required functionality.

Test
Q.20 Easy OOP in C#
Which statement is TRUE about abstract methods in C#?
A Abstract methods must be implemented in the base class
B Abstract methods cannot have any body and must be implemented in derived classes
C Abstract methods are only for static classes
D Abstract methods can be private
Correct Answer:  B. Abstract methods cannot have any body and must be implemented in derived classes
EXPLANATION

Abstract methods have no implementation in the abstract class and force derived classes to provide their own implementation. They cannot be private as they must be overridable.

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