✅ .NET Core Interview Questions with Examples (Easy Explanations)
🔹 1. General .NET Core Basics
Q1. What is .NET Core?
👉 Answer:
.NET Core is like the engine of your application. It lets you build apps that run on Windows, Linux, and Mac.
Example:
This creates and runs a simple console app.
Q2. Difference between .NET Framework and .NET Core?
👉 Answer:
-
.NET Framework: Windows-only (old car 🚗 that only runs on one type of road).
-
.NET Core: Cross-platform, modern, faster (new car 🏎 that runs anywhere).
Q3. What is Middleware in ASP.NET Core?
👉 Answer:
Middleware is like checkpoints in a toll road 🚦. Each one checks/does something before passing the request.
Example:
Here the middleware logs before and after handling a request.
Q4. What is Kestrel?
👉 Answer:
Kestrel is the built-in web server for .NET Core.
Think of it as the engine that runs your website before IIS/NGINX serves it to the world.
🔹 2. C# Language Features
Q5. What are Records in C# 9?
👉 Answer:
Records are like data containers – they store values and are immutable (cannot be changed once created).
Example:
Q6. Difference between Task and ValueTask?
👉 Answer:
-
Task = always creates an object (extra memory).
-
ValueTask = avoids extra memory if the result is already available.
Example:
Q7. What is Pattern Matching?
👉 Answer:
Pattern matching helps check types in a simpler way.
Example:
🔹 3. Dependency Injection
Q8. What is DI (Dependency Injection)?
👉 Answer:
Instead of a class creating its own dependencies, they are given from outside. This makes testing and maintenance easier.
Without DI:
With DI:
In .NET Core:
Q9. What’s the difference between AddTransient, AddScoped, AddSingleton?
👉 Answer:
-
Transient – new object every time.
-
Scoped – one object per request.
-
Singleton – one object for the whole app.
Example:
Imagine coffee cups:
-
Transient = new cup for every sip ☕
-
Scoped = one cup per customer 👤
-
Singleton = one thermos for the whole café 🏪
🔹 4. Entity Framework Core
Q10. What is AsNoTracking()?
👉 Answer:
When fetching data from DB, EF tracks changes by default.
If you don’t need tracking (read-only), use AsNoTracking() for faster performance.
Example:
Q11. What is a Migration in EF Core?
👉 Answer:
Migration = a version update for the database when your model changes.
Example:
This adds a new column (Email) to the User table.
🔹 5. ASP.NET Core Features
Q12. What is Routing?
👉 Answer:
Routing decides which function handles which URL.
Example:
Now calling http://localhost/api/hello → returns "Hello World!".
Q13. What is a Minimal API (from .NET 6)?
👉 Answer:
A simpler way to build APIs without controllers.
Example:
Q14. What is SignalR?
👉 Answer:
SignalR is used for real-time communication (like WhatsApp chat).
Example:
-
User A sends a message → instantly pushed to User B.
🔹 6. Security
Q15. What is JWT Authentication?
👉 Answer:
JWT (JSON Web Token) = digital ticket 🎟 that proves identity.
Instead of saving session on server, JWT is sent with every request.
Example JWT looks like:
Q16. What is CORS?
👉 Answer:
CORS = allows or blocks cross-domain requests.
For example: if your API is on api.com but frontend is on myapp.com.
Code Example:
That’s the style:
-
Simple definition
-
Analogy (real-life example)
-
Code snippet
Comments
Post a Comment