Interview Questions and Answers
What Is MVC?
MVC stands for Model-View-Controller. It is a design pattern used for developing web
applications:
- Model: Handles data and business logic.
- View: Displays data (UI).
- Controller: Handles user input, updates model & view.
How can we pass data from one controller to another?
You can pass data using:
- TempData: Stores data temporarily during redirect.
- Route Values: Pass values through URL.
- Session: Stores data across requests.
- Query String: Use URL parameters.
What Is Difference Between ViewData vs TempData in MVC?
- ViewData: Passes data from Controller to View. Valid only for the current request.
- TempData: Stores data until it's read, works across redirects (multiple requests).
What Is Difference Between For Loop vs Foreach Loop in C#?
- For Loop: Use when you need index or want to modify elements.
- Foreach Loop: Use to iterate over collections (read-only). Simpler and safer.
What Is Garbage Collector (GC) in C#?
Garbage Collector automatically frees memory by destroying unused objects, improving
performance and preventing memory leaks.
What Is Difference Between Value Type vs Reference Type in C#?
- Value Type: Stores data directly (stack). Example: int, float, bool.
- Reference Type: Stores reference to data (heap). Example: class, string, object.
What Is Difference Between First() and FirstOrDefault()?
- First(): Returns the first element. Throws error if none found.
- FirstOrDefault(): Returns the first element or null/default if none found. Safer.
What are the Entity Framework (EF) approaches in .Net?
1. Database First – Start with database, generate models.
2. Model First – Create model diagram, generate DB.
3. Code First – Write code classes, EF creates DB.
What happens in database first?
EF reads existing database, generates model classes and DbContext. Developers use those
classes to interact with the DB.
What is primary keys and foreign keys?
- Primary Key: Uniquely identifies each row in a table.
- Foreign Key: Links one table to another using a primary key.
What Is Multiple Unique Constraints?
A table can have multiple unique constraints to ensure that specific columns contain only
unique values, but only one primary key.
Find the second largest number in array (C# Example):
int[] arr = { 5, 10, 20, 8, 20 };
int first = int.MinValue, second = int.MinValue;
foreach (int num in arr)
{
if (num > first)
{
second = first;
first = num;
}
else if (num > second && num != first)
{
second = num;
}
}
Console.WriteLine("Second Largest: " + second);
What is ASP .NET?
ASP.NET is a web development framework by Microsoft for building dynamic web apps,
websites, and services using .NET and C#.
Session vs Cookies Difference?
- Session: Stores data on the server, expires on timeout.
- Cookie: Stores data on client browser, size limit (~4KB), can persist longer.
What is Http handler?
HTTP Handler is a component that handles HTTP requests. Example: .ashx files handle
requests directly for images, files, or dynamic output.
What is Entity Framework?
Entity Framework (EF) is an ORM tool for .NET. It allows developers to work with databases
using C# classes instead of SQL.
What is Dependencies injection?
It’s a design pattern used to inject object dependencies at runtime instead of hardcoding
them. Makes code more flexible and testable.
What is a Web API?
Web API is a framework to build HTTP services (RESTful APIs) in .NET, used to expose data
and services to clients (web, mobile).
What is Postman?
Postman is a tool used to test APIs by sending HTTP requests (GET, POST, etc.) and viewing
responses.
What is an HTTP Status Code?
HTTP Status Code is a 3-digit response code:
- 200 = OK
- 404 = Not Found
- 500 = Server Error
Used to indicate result of HTTP request.
Postman Which Format?
Postman sends/receives data in formats like:
- JSON (commonly used)
- XML
- Text
JSON Full Form?
JSON = JavaScript Object Notation
It is a lightweight data-interchange format, easy for humans to read and machines to parse.