Home Subjects C# Programming

C# Programming

C# and .NET for campus placement

60 Q 4 Topics Take Mock Test
Advertisement
Difficulty: All Easy Medium Hard 21–30 of 60
Topics in C# Programming
Q.21 Hard OOP in C#
A gaming application needs to implement different weapons (Sword, Gun, Bow) with different attack methods. Which approach is most maintainable?
A Create separate classes for each weapon inheriting from base Weapon class
B Use a single class with if-else statements for each weapon type
C Use global functions for each weapon
D Use only static methods
Correct Answer:  A. Create separate classes for each weapon inheriting from base Weapon class
EXPLANATION

Inheritance and polymorphism provide better maintainability, scalability, and follow SOLID principles compared to conditional logic.

Test
Q.22 Hard ASP.NET Basics
A developer needs to create a RESTful API that returns JSON data. Which ASP.NET approach is most suitable?
A ASP.NET Core Web API with [ApiController]
B ASP.NET Web Forms with controls
C Classic ASP with VBScript
D ASP.NET MVC Views only
Correct Answer:  A. ASP.NET Core Web API with [ApiController]
EXPLANATION

ASP.NET Core Web API with [ApiController] attribute is the modern approach for building RESTful APIs that return JSON.

Test
Q.23 Hard ASP.NET Basics
In ASP.NET Core, which method is used to register services in the dependency injection container?
A services.AddScoped(), services.AddSingleton(), services.AddTransient()
B services.Register()
C services.Inject()
D services.Configure()
Correct Answer:  A. services.AddScoped(), services.AddSingleton(), services.AddTransient()
EXPLANATION

AddScoped, AddSingleton, and AddTransient are methods to register services with different lifetimes in ASP.NET Core DI.

Test
Q.24 Hard ASP.NET Basics
An e-commerce application needs to handle concurrent user requests efficiently. Which ASP.NET Core feature is most suitable?
A Async/Await with Task-based operations
B Synchronous request processing
C Single-threaded execution
D Blocking I/O operations
Correct Answer:  A. Async/Await with Task-based operations
EXPLANATION

Async/Await enables non-blocking I/O operations, allowing ASP.NET Core to handle more concurrent requests efficiently.

Test
Q.25 Hard ASP.NET Basics
What is the correct order of Page Lifecycle events in ASP.NET Web Forms?
A Init → Load → EventHandling → Render → Unload
B Load → Init → EventHandling → Render → Unload
C Init → Load → Render → EventHandling → Unload
D Load → Init → Render → EventHandling → Unload
Correct Answer:  A. Init → Load → EventHandling → Render → Unload
EXPLANATION

ASP.NET Web Forms lifecycle: Init → Load → Event Handling (ViewState restored) → Render → Unload.

Test
Q.26 Hard ASP.NET Basics
A web application needs to store a user preference that persists across multiple browser sessions. Which state management technique is most appropriate?
A Database with user ID
B ViewState
C Session State
D Application State
Correct Answer:  A. Database with user ID
EXPLANATION

For persistent data across multiple sessions, database storage is the best approach. Session State is temporary and Application State is server-wide.

Test
Q.27 Hard OOP in C#
In a hospital management system, Doctor and Nurse classes need to perform a common Logout() operation but have different Login() procedures. What is the best OOP approach?
A Create a base class with virtual Logout() and abstract Login()
B Create separate classes with no inheritance
C Create an interface with both methods
D Use static methods for common operations
Correct Answer:  A. Create a base class with virtual Logout() and abstract Login()
EXPLANATION

A base class with virtual Logout() allows common implementation, while abstract Login() forces derived classes to provide their own implementation. This combines code reuse with flexibility.

Test
Q.28 Hard OOP in C#
A banking application uses inheritance where Account is the parent class and SavingsAccount, CurrentAccount are derived classes. Each has different withdrawal rules. Which design principle is being followed?
A Single Responsibility Principle (SRP)
B Open/Closed Principle (OCP)
C Liskov Substitution Principle (LSP)
D Dependency Inversion Principle (DIP)
Correct Answer:  B. Open/Closed Principle (OCP)
EXPLANATION

Open/Closed Principle states that classes should be open for extension (SavingsAccount, CurrentAccount extend Account) but closed for modification (Account class rules remain unchanged). This is a classic example of OCP.

Test
Q.29 Hard OOP in C#
What will happen if you try to override a non-virtual method in a derived class in C#?
A Compilation error - cannot override non-virtual methods
B The method will be hidden using the 'new' keyword implicitly
C Runtime error will occur
D Compilation warning, but it will compile and run
Correct Answer:  B. The method will be hidden using the 'new' keyword implicitly
EXPLANATION

In C#, if you attempt to override a non-virtual method without using 'new' keyword, the compiler issues a warning but the method is hidden (not overridden). Using 'new' keyword explicitly hides the base method.

Test
Q.30 Hard OOP in C#
A logging system needs to handle multiple logger types (File, Database, Console) interchangeably. Which design pattern combined with polymorphism best suits this?
A Singleton with inheritance
B Strategy pattern with interface implementation
C Factory pattern only
D Observer pattern exclusively
Correct Answer:  B. Strategy pattern with interface implementation
EXPLANATION

Strategy pattern defines a family of algorithms (logger types) and makes them interchangeable through interface polymorphism, allowing runtime selection.

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