50 ASP.
NET Core & C# Interview Questions (Simple Answers)
1. What is a namespace in C#?
Namespace is used to organize classes and other types, and to avoid name conflicts.
2. What are value types and reference types?
Value types store data directly; reference types store a reference to the data's memory address.
3. What is the use of the 'var' keyword in C#?
'var' allows the compiler to determine the type of a variable at compile-time.
4. What are string interpolation and concatenation?
Interpolation uses $"{}" to insert variables; concatenation uses '+' to join strings.
5. What are if, switch, and loop constructs in C#?
They control flow: if checks conditions, switch selects cases, loops repeat actions.
6. What are Collection Classes in C#?
They are predefined classes like List, Dictionary, HashSet to store groups of objects.
7. How does exception handling work in C#?
Use try-catch-finally blocks to handle and manage errors gracefully.
8. What are constructors?
Constructors initialize objects and can be parameterless or parameterized.
9. What is an Access Modifier?
They define access levels like public, private, protected, internal.
10. What is an interface in C#?
Interface defines a contract. Classes that implement it must define its members.
11. What is ASP.NET Core?
ASP.NET Core is a cross-platform, high-performance framework for building modern web apps.
12. What are the advantages of ASP.NET Core?
Cross-platform, high-performance, modular, cloud-ready, and open-source.
13. What is the MVC pattern?
Model-View-Controller separates application into 3 parts for better organization.
14. What is Middleware?
Middleware are components that handle requests and responses in the pipeline.
15. What is the use of the Startup class?
It configures services and middleware during application startup.
16. What is the Program.cs file?
It is the entry point of the ASP.NET Core application.
17. What is the Request-Response pipeline?
It's a sequence of middleware that processes HTTP requests and responses.
18. What are Areas in ASP.NET Core?
Areas help organize related functionalities into separate sections.
19. What is Razor view engine?
Razor is a markup syntax for embedding server code into HTML in views.
20. What is a Partial View?
Partial Views are reusable parts of a view to render a portion of HTML.
21. What is a Layout Page?
Layout pages define a common template (like header/footer) for views.
22. What are HTML Helpers?
HTML Helpers simplify HTML markup generation in Razor views.
23. What are Tag Helpers?
Tag Helpers are server-side components that create and modify HTML elements.
24. What is the difference between URL Helper and HTML Helper?
URL helpers build URLs; HTML helpers generate HTML tags.
25. How to create a custom Tag Helper?
Inherit from TagHelper class and override Process method.
26. What is ViewData?
ViewData is a dictionary to pass data from controller to view.
27. What is ViewBag?
ViewBag is a dynamic wrapper around ViewData to pass data to views.
28. What is TempData?
TempData stores data temporarily during a redirect between actions.
29. What is Data Annotation in ASP.NET Core?
Data Annotations are attributes used to validate model properties.
30. How does server-side validation work?
It checks validation rules on the server after form submission.
31. What is client-side validation?
It checks data using JavaScript before the form is submitted.
32. What is model binding?
It maps form values to action method parameters or model properties.
33. What is IFormCollection?
It's used to read form data submitted in a POST request.
34. What is the Bind attribute?
It specifies which properties to include/exclude from binding.
35. What are ways to pass data to views?
Use ViewData, ViewBag, TempData, and strongly typed models.
36. What is ModelState?
ModelState tracks the state of model binding and validation.
37. What is Anti-forgery token?
It protects against CSRF attacks by validating submitted forms.
38. What is routing in ASP.NET Core?
Routing maps URLs to controller actions.
39. What is attribute routing?
Attribute routing uses attributes to define routes directly on actions.
40. What is a routing constraint?
It restricts how parameters in routes can be matched.
41. What is ADO.NET?
ADO.NET is a data access framework for connecting to databases.
42. What is a Connection object?
It establishes a connection to the database.
43. What is a Command object?
It is used to execute SQL queries or stored procedures.
44. What is a DataReader?
DataReader is a forward-only, read-only stream of data from the database.
45. What are .NET Data Providers?
They are components that interact with data sources like SQL Server.
46. What is a Query String?
It's a way to pass data through the URL using key-value pairs.
47. What is Session in ASP.NET Core?
Session stores user data between requests.
48. How to enable session in ASP.NET Core?
Use AddSession() in ConfigureServices and app.UseSession() in Configure.
49. What is cookie-based state management?
Cookies store data on the client to maintain user-specific info.
50. What is TempData vs Session?
TempData is short-lived (1 redirect), Session lasts until timeout or logout.