Top 50+ Dot Net MCQs with Answers
Boost your .NET knowledge with Top 50+ Dot Net MCQs with Answers, covering key concepts, frameworks, and best practices for interviews and exams.
1. What is the default value of the Boolean variable in c#?
a) True
b) False
c) Null
d) 0
Answer: b) False
2. What is the use of using keyword in c#?
a) To define a namespace
b) To import classes from a library
c) To initialize a variable
d) To define an alias for a namespace
Answer: b) To import classes from a library
3. What is the value type from below?
a) String
b) Object
c) Int
d) Array
Answer: c) Int
4. Which method starts the thread?
a) Start()
b) Run()
c) Begin()
d) Execute()
Answer: a) Start()
5. What will be the output of the following C# code?
int a = 5;
int b = 2;
Console.WriteLine(a / b);
- a) 2
b) 2.5
c) 0
d) Error
Answer: a) 2
6. What is the default access modifier for fields in c#?
a) Public
b) Private
c) Protected
d) Internal
Answer: b) Private
7. Which keyword is used to declare a constant?
a) final
b) const
c) static
d) readonly
Answer: b) const
8. What is the base class in C#?
a) Object
b) Base
c) System
d) ValueType
Answer: a) Object
9. Which of the following statements is true about value types in C#?
a) They are stored in the stack memory
b) They are reference types
c) They are always initialized to null
d) They support inheritance
Answer: a) They are stored in the stack memory
10. How do we define the method in c#?
a) method void Add()
b) void Add() { }
c) void Add()
d) def void Add() {}
Answer: b) void Add() { }
Note: Explore A Comprehensive Guide to ASP.NET, covering key features, frameworks, and best practices to build dynamic, secure, and scalable web applications.
11. What is the use of try and catch block in C#?
a) Memory leaks
b) Exceptions
c) Data binding
d) Polymorphism
Answer: b) Exceptions
12. How can we stop the class from getting it inherited?
a) sealed
b) static
c) readonly
d) abstract
Answer: a) sealed
13. What is ASP.NET?
a) A programming language
b) A framework for building web applications
c) A web server
d) A type of database
Answer: b) A framework for building web applications
14. Which one from below executes page requests in ASP.net?
a) WebForm
b) Server Control
c) Page Class
d) Request Object
Answer: c) Page Class
15. Which of the following is an incorrect event in the ASP.NET page lifecycle?
a) Page_Load
b) Page_PreRender
c) Page_Init
d) Page_Unload
e) Page_Finish
Answer: e) Page_Finish
16. what is the default file extension for a web page in ASP.net?
a) .html
b) .aspx
c) .php
d) .js
Answer: b) .aspx
17. How is user-specific data stored in ASP.net?
a) ViewState
b) SessionState
c) ApplicationState
d) Cookie
Answer: b) SessionState
18. Which of the following controls is used to display read-only data in a grid format?
a) TextBox
b) Label
c) GridView
d) DropDownList
Answer: c) GridView
19. What is the use of the ‘global.asax’ file in an ASP.NET?
a) Contains global variables
b) Handles application-level events
c) Stores configuration settings
d) Defines routes for the application
Answer: b) Handles application-level events
20. Which of the following is NOT a feature of ASP.NET Web Forms?
a) Separation of Concerns
b) Server-side code execution
c) ViewState
d) Supports RESTful architecture
Answer: d) Supports RESTful architecture
21. Which method is used by default for ASP.net form submission?
a) GET
b) POST
c) PUT
d) PATCH
Answer: b) POST
22. Which class is used to manage authentication and authorization in ASP.net?
a) FormsAuthentication
b) AuthenticationManager
c) HttpContext
d) SecurityManager
Answer: a) FormsAuthentication
23. Which of the following is the default convention for Controller class names in ASP.NET MVC?
a) ControllerName.cs
b) ControllerNameController.cs
c) NameController.cs
d) ControllerNameMvc.cs
Answer: b) ControllerNameController.cs
24. Which file is used to configure routes in an ASP.NET MVC application?
a) Web.config
b) Global.asax
c) Route.config
d) RouteHandler.cs
Answer: b) Global.asax
25. what is the purpose of the ViewData dictionary in ASP.net MVC?
a) To pass data from the Controller to the View
b) To store session data
c) To store global settings
d) To configure routes
Answer: a) To pass data from the Controller to the View
26. Which method is used to return data in the form of a view in a controller action?
a) View()
b) Redirect()
c) Json()
d) ActionResult()
Answer: a) View()
27. What does MVC stand for in the context of ASP.NET MVC?
a) Model View Controller
b) Model View Communication
c) Memory View Control
d) Multiple Variable Controller
Answer: a) Model View Controller
28. What is the correct syntax for creating a route in ASP.net MVC?
a) routes.MapRoute(“Home”, “home/index”);
b) RouteConfig.MapRoute(“Home”, “home/index”);
c) routes.MapRoute(“default”, “{controller}/{action}/{id}”);
d) Route.MapRoute(“default”, “{controller}/{action}/{id}”);
Answer: c) routes.MapRoute(“default”, “{controller}/{action}/{id}”);
29. Which of the following is used to define model properties in ASP.NET MVC?
a) Model class
b) View class
c) Controller class
d) Action class
Answer: a) Model class
30. What is the purpose of the ‘Html.BeginForm()’ method in ASP.NET MVC?
A) To start a new controller
b) To create a view
c) To start a form in the view
d) To initialize a model
Answer: c) To start a form in the view
Note: Discover the Future of .NET, exploring upcoming features, advancements, and how it continues to evolve for modern app development across platforms.
31. What is used to display error messages in ASP.net MVC?
A) ViewBag
B) ViewData
C) TempData
D) All of the above
Answer: d) All of the above
32. Which method is used to redirect a user to another action in ASP.NET MVC?
A) Redirect()
B) RedirectToAction()
C) RedirectToRoute()
D) ActionResult.Redirect()
Answer: b) RedirectToAction()
33. What type of data does the ‘JsonResult’ return in ASP.NET MVC?
A) Plain text
B) HTML content
C) JSON data
D) XML data
Answer: c) JSON data
34. Which of the following is used to store values that need to persist across requests in ASP.NET MVC?
A) ViewData
B) Session
C) TempData
D) Cookies
Answer: b) Session
35. In ASP.NET MVC, which attribute is used to mark a method as a POST action?
A) [HttpPost]
B) [HttpGet]
C) [Action]
D) [ActionResult]
Answer: a) [HttpPost]
36. Which is the default folder for storing views in an ASP.NET MVC project?
A) Views
B) Content
C) Pages
D) Resources
Answer: a) Views
37. What is .NET Core?
A) A web development framework
B) A cross-platform runtime for building modern apps
C) A cloud-based service
D) A desktop application framework
Answer: B) A cross-platform runtime for building modern apps
38. Which one is NOT a valid .NET Core project template?
A) Console App
B) ASP.NET Core Web Application
C) Windows Forms App
D) Class Library
Answer: C) Windows Forms App
39. Which of the following is a feature of .NET Core?
A) Cross-platform support
B) Dependency Injection (DI) built-in
C) Modular framework
D) All of the above
Answer: D) All of the above
40. Which command helps to create a new .NET Core console application?
A) dotnet new console
B) dotnet run new console
C) dotnet create console
D) dotnet build console
Answer: A) dotnet new console
41. Which version of .NET Core is used in .NET 5?
A) .NET Core 3.1
B) .NET Framework 4.8
C) .NET 5 is a unified version of .NET Core
D) .NET Core 2.0
Answer: C) .NET 5 is a unified version of .NET Core
42. Which of the following is the main configuration file for a .NET Core application?
A) app.config
B) web.config
C) appsettings.json
D) config.json
Answer: C) appsettings.json
43. Which command is used to restore the NuGet packages in a .NET Core project?
A) dotnet restore
B) dotnet fetch
C) dotnet get
D) dotnet install
Answer: A) dotnet restore
44. What is the default web server used by ASP.NET Core?
A) Kestrel
B) IIS
C) Apache
D) Nginx
Answer: A) Kestrel
45. How can you inject dependencies into a class in .net core?
A) By using constructors
B) By using a property
C) By using a method
D) All of the above
Answer: D) All of the above
46. What do you use to manage packages in .NET Core projects?
A) npm
B) NuGet
C) Maven
D) Composer
Answer: B) NuGet
47. Which HTTP method is used to retrieve data from a REST API in .NET?
A) POST
B) GET
C) PUT
D) DELETE
Answer: B) GET
48. In .NET, what attribute is used to mark a method as handling HTTP GET requests?
A) [HttpMethod(“GET”)]
B) [HttpGet]
C) [HttpPost]
D) [Route(“GET”)]
Answer: B) [HttpGet]
49. Which namespace do you need to include to work with REST APIs in ASP.NET Core?
A) System.Net.Http
B) Microsoft.AspNetCore.Mvc
C) System.Web.Http
D) Microsoft.Rest
Answer: B) Microsoft.AspNetCore.Mvc
50. What is the default response status code for a successful HTTP request in REST API (in .NET)?
A) 200 OK
B) 201 Created
C) 400 Bad Request
D) 500 Internal Server Error
Answer: A) 200 OK
51. Which of the following can be used in .NET to perform routing in a REST API?
A) [Route]
B) [HttpRequest]
C) [Service]
D) [Path]
Answer: A) [Route]
52. In .NET Core, which method is used to add services to the dependency injection container in Startup.cs?
A) ConfigureServices()
B) AddServices()
C) ConfigureAPI()
D) RegisterServices()
Answer: A) ConfigureServices()
53. Which of the following is used to create an instance of a controller in ASP.NET Core REST API?
A) IHttpRequestFactory
B) IActionResult
C) IControllerFactory
D) ControllerBase
Answer: C) IControllerFactory
54. In a .NET Web API, which of the following is used to send a response with HTTP status code 404 (Not Found)?
A) NotFound()
B) StatusCode(404)
C) ResponseNotFound()
D) HttpNotFound()
Answer: A) NotFound()
55. In .NET REST API, what is used to accept JSON data in a POST request?
A) [Consumes(“application/xml”)]
B) [Consumes(“application/json”)]
C) [Produces(“application/json”)]
D) [Produces(“application/xml”)]
Answer: B) [Consumes(“application/json”)]
56. Which attribute would you use to allow a PUT request on a specific route in .NET Core?
A) [HttpPut]
B) [Put]
C) [HttpPatch]
D) [HttpRoute]
Answer: A) [HttpPut]
Do visit our channel to get more information: Click Here
Author:-
Anil Giri
Call the Trainer and Book your free demo Class For Dot Net Call now!!!
| SevenMentor Pvt Ltd.
© Copyright 2021 | SevenMentor Pvt Ltd.