Top 25 .NET Core (C#) Interview Questions and Answers

Preparing for a .NET Core (C#) interview? You’ve come to the right place!

In today’s competitive tech industry, having a solid grasp of .NET Core fundamentals and advanced C# concepts are essential to crack interviews and land your dream job.

This guide covers the top 25 most commonly asked .NET Core (C#) interview questions, each explained with clear examples to help you understand concepts better and answer with confidence.

Whether you’re a fresher, an experienced developer, or someone switching to .NET Core development, these questions will sharpen your technical skills and boost your chances of success.

Let’s dive in and master .NET Core interview preparation!

1. What is .NET Core?

.NET Core is an open-source, cross-platform framework developed by Microsoft for building modern, cloud-based, internet-connected applications.

Example: You can build a web API using ASP.NET Core that runs on Windows, Linux, or Mac.

 

2. Difference between .NET Core and .NET Framework?

.NET Core

.NET Framework

Cross-platform

Windows-only

Lightweight & modular

Monolithic

CLI tools available

Mostly GUI tools

Supports microservices

Primarily used for large monolithic apps

 

3. What are the main components of .NET Core?

  • CoreCLR – The runtime (handles execution)

     

  • CoreFX – Set of libraries (collections, IO, XML, etc.)

     

  • ASP.NET Core – Web application framework

     

  • Entity Framework Core – ORM for database operations

     

4. What is Middleware in ASP.NET Core?

Middleware is software that’s assembled into the request pipeline to handle requests and responses.

Example:

app.Use(async (context, next) => {

    Console.WriteLine(“Before next middleware”);

    await next.Invoke();

    Console.WriteLine(“After next middleware”);

});

 

5. Explain Dependency Injection in .NET Core.

.NET Core has built-in support for Dependency Injection (DI). It allows for loosely coupled code.

Example:

services.AddScoped<IProductService, ProductService>();

Now, IProductService can be injected wherever needed.

 

6. What is Kestrel?

Kestrel is the cross-platform web server for ASP.NET Core applications.

 

7. What is a Service Lifetime in .NET Core?

  • Transient – New instance every time

     

  • Scoped – One instance per request

     

  • Singleton – One instance for the entire app

     

Example:

services.AddSingleton<ILogger, Logger>();

 

8. How is Configuration handled in .NET Core?

Configuration in .NET Core can come from various sources: JSON files, environment variables, command-line arguments, etc.

Example:

var mySetting = Configuration[“MySettings:Setting1”];

 

9. What are Tag Helpers in ASP.NET Core?

Tag Helpers are server-side components that create and render HTML elements.

Example:

<environment include=”Development”>

    <script src=”dev-script.js”></script>

</environment>

 

10. What is Entity Framework Core?

EF Core is an ORM (Object Relational Mapper) to work with databases using .NET objects.

Example:

 

dbContext.Products.Add(new Product { Name = “Phone” });

dbContext.SaveChanges();

 

11. How to perform database migration in EF Core?

dotnet ef migrations add InitialCreate

dotnet ef database update

 

12. What is the Startup class?

The Startup.cs file configures services and the app’s request pipeline.

Example:

public void ConfigureServices(IServiceCollection services)

{

    services.AddControllers();

}

 

13. Explain the Program.cs file in .NET Core.

It contains the Main() method to configure and start the application.

Example:

var builder = WebApplication.CreateBuilder(args);

var app = builder.Build();

app.Run();

 

14. How do you handle exceptions globally in ASP.NET Core?

Use Middleware like UseExceptionHandler or custom middleware.

Example:

app.UseExceptionHandler(“/Home/Error”);

 

15. What is the difference between IApplicationBuilder and IWebHostBuilder?

  • IApplicationBuilder – Used to build the app’s request pipeline.

     

  • IWebHostBuilder – Used to set up the host (server) for the app.

 

16. What are Filters in ASP.NET Core MVC?

Filters allow code to run before or after specific stages of request processing (like Authorization, Action, Result, Exception).

Example:

public class MyActionFilter : IActionFilter

{

    public void OnActionExecuting(ActionExecutingContext context) { }

    public void OnActionExecuted(ActionExecutedContext context) { }

}

 

17. What are Razor Pages?

Razor Pages is a simplified, page-based coding model for building web UI.

Example: Index.cshtml and its code-behind Index.cshtml.cs

 

18. What is the purpose of appsettings.json?

It is the default configuration file used to store settings.

Example:

{

  “ConnectionStrings”: {

    “DefaultConnection”: “Server=.;Database=myDb;Trusted_Connection=True;”

  }

}

 

19. Explain routing in ASP.NET Core.

Routing maps incoming requests to route handlers (controllers/actions).

Example:

app.MapControllerRoute(

    name: “default”,

    pattern: “{controller=Home}/{action=Index}/{id?}”);

 

20. How do you implement Authentication and Authorization in .NET Core?

  • Authentication checks who you are.
  • Authorization checks what you can do.

Example:

services.AddAuthentication(“CookieAuth”).AddCookie(“CookieAuth”, config => {

    config.LoginPath = “/Home/Authenticate”;

});

 

21. What is the difference between Asynchronous and Synchronous programming?

  • Synchronous: Blocks until the operation finishes.

     

  • Asynchronous: Non-blocking; frees up the thread to handle other tasks.

     

Example:

await dbContext.Products.ToListAsync();

 

22. What is SignalR in ASP.NET Core?

SignalR is a library for real-time web functionality (like chat apps).

Example:

services.AddSignalR();

app.MapHub<ChatHub>(“/chatHub”);

 

23. What are Minimal APIs in .NET 6/7?

Minimal APIs allow you to create APIs with minimal overhead.

Example:

app.MapGet(“/”, () => “Hello World!”);

 

24. What are Hosted Services in .NET Core?

Background services running with the app (like timed jobs).

Example:

public class MyHostedService : IHostedService

{

    public Task StartAsync(CancellationToken cancellationToken) { }

    public Task StopAsync(CancellationToken cancellationToken) { }

}

 

25. What is gRPC in .NET Core?

gRPC is a high-performance RPC framework for communication between services.

Example: Define .proto file for message format and auto-generate C# client and server code.

 

 

Mastering these .NET Core (C#) interview questions with practical examples will give you a strong edge in any technical interview.

Understanding key concepts like Dependency Injection, Middleware, Entity Framework Core, Minimal APIs, and gRPC is crucial for building scalable and modern applications — and impressing your interviewers!

Keep practicing, work on real-world projects, and stay updated with the latest features in .NET Core to stay ahead in your career.

Bookmark this page and revisit it often for quick revision before your next interview.

Good luck with your .NET Core journey — you’ve got this!

Leave a Reply

Your email address will not be published. Required fields are marked *