.NET Interview Questions and Answers for Freshers and Experienced (48 Questions)

Quick answer: These 48 .NET interview questions and answers cover what is asked most in .NET developer, C# developer and ASP.NET Core interviews: .NET basics, C# fundamentals, OOP, delegates and LINQ, memory and asynchronous programming, ASP.NET Core, and Entity Framework Core. Key answers include short code examples.

Read each answer, then close the page and explain it aloud in two or three sentences. That is exactly what interviewers check.

Contents

1. .NET Basics Interview Questions

Q1. What is .NET?

.NET is a free, open-source developer platform from Microsoft for building web, desktop, mobile, cloud and game applications. Modern .NET (from .NET 5 onwards, including .NET 8 and later) is cross-platform and runs on Windows, Linux and macOS.

Q2. What is the difference between .NET Framework, .NET Core and modern .NET?

.NET Framework is the original Windows-only platform, now only maintained. .NET Core was the cross-platform, open-source rewrite. From .NET 5 onwards they were unified as simply '.NET', which is where all new development happens.

Q3. What is the CLR?

The Common Language Runtime is the execution engine of .NET. It loads compiled code, compiles it to machine code with the JIT compiler, manages memory through garbage collection, and handles exceptions, type safety and security.

Q4. What are IL and JIT?

C# code is compiled into Intermediate Language (IL), stored in assemblies. At run time, the Just-In-Time compiler converts IL into native machine code. .NET also supports ahead-of-time (AOT) compilation for faster startup.

Q5. What is the difference between managed and unmanaged code?

Managed code runs under the CLR, which provides garbage collection and type safety, as with C#. Unmanaged code, such as native C++ or Windows APIs, runs outside the CLR and must manage its own memory.

Q6. What is an assembly?

An assembly is the compiled unit of deployment in .NET, a .dll or .exe file containing IL code, metadata and a manifest describing its version and dependencies.

Q7. What is NuGet?

NuGet is the package manager for .NET. You add libraries such as Entity Framework Core or Newtonsoft.Json with dotnet add package or the Visual Studio package manager.

2. C# Fundamentals Interview Questions

Q8. What is the difference between value types and reference types?

Value types (int, double, bool, struct, enum) hold their data directly and are copied on assignment. Reference types (class, string, array, delegate) hold a reference to an object on the managed heap, so two variables can point to the same object.

Q9. What are boxing and unboxing?

Boxing converts a value type to object, copying it onto the heap. Unboxing extracts the value type back. Both cost performance, so generics are preferred over storing value types as object.

Q10. What is the difference between const and readonly?

const values are fixed at compile time and are implicitly static. readonly fields can be assigned at declaration or in a constructor, so their value can be decided at run time.

Q11. What is the difference between string and StringBuilder?

string is immutable, so every change creates a new object. StringBuilder is mutable and much faster for building strings in loops.

Q12. What is the difference between ref and out?

Both pass arguments by reference. A ref argument must be initialised before the call; an out argument need not be, but the method must assign it before returning.

Q13. What are nullable types?

Nullable value types, such as int?, can hold null in addition to their normal range. Nullable reference types (enabled in modern projects) make the compiler warn when a reference might be null.

Q14. What is the difference between an abstract class and an interface in C#?

An abstract class can have fields, constructors and implemented methods, and a class can inherit only one. An interface defines a contract that a class can implement many of; since C# 8, interfaces can also have default method implementations.

Q15. What are access modifiers in C#?

public, private, protected, internal (same assembly), protected internal and private protected.

Q16. What are properties in C#?

Properties expose fields through get and set accessors, with optional logic. Auto-implemented properties such as public string Name { get; set; } create the backing field automatically.

Q17. What is the difference between a class, a struct and a record?

A class is a reference type. A struct is a value type suited to small data. A record (C# 9) is designed for immutable data and compares by value, so two records with the same values are equal.

3. OOP, Delegates and LINQ Interview Questions

Q18. What are the four pillars of OOP in C#?

Encapsulation, abstraction, inheritance and polymorphism. C# supports single class inheritance and multiple interface inheritance.

Q19. What is the difference between method overloading and overriding?

Overloading means methods with the same name but different parameters in one class. Overriding means a derived class replaces a virtual or abstract base method using the override keyword.

Q20. What is the difference between new and override?

override replaces a virtual method, so a base-class reference calls the derived version. new hides the base method, so a base-class reference still calls the base version.

Q21. What is a delegate?

A delegate is a type-safe reference to a method. Func<> returns a value, Action<> returns nothing, and Predicate<T> returns bool. Delegates are the basis of events and lambda expressions.

Q22. What are events?

Events let a class notify other classes when something happens, using delegates. Subscribers attach handlers with += and detach them with -=.

Q23. What is LINQ?

Language Integrated Query provides query operators such as Where, Select, OrderBy, GroupBy and Join to query collections, databases and XML in C# code.

var topStudents = students
    .Where(s => s.Marks >= 75)
    .OrderByDescending(s => s.Marks)
    .Select(s => s.Name)
    .ToList();

Q24. What is the difference between IEnumerable and IQueryable?

IEnumerable works in memory, so filtering happens after the data is loaded. IQueryable builds an expression that a provider such as Entity Framework translates into SQL, so filtering happens in the database.

Q25. What are generics?

Generics let you write type-safe classes and methods that work with any type, such as List<T> and Dictionary<TKey, TValue>, without boxing or casting.

Q26. What are extension methods?

Extension methods add new methods to existing types without changing them. They are static methods in a static class whose first parameter uses the this keyword. LINQ is built with them.

Preparing for a .NET interview? We run live one-to-one classes and mock interviews in C#, .NET and back-end development, arranged around your free time. Chat on WhatsApp.

4. Memory and Asynchronous Programming Interview Questions

Q27. How does garbage collection work in .NET?

The garbage collector frees memory of objects that are no longer reachable. It uses three generations (0, 1 and 2): new objects start in generation 0, and survivors are promoted, because most objects die young.

Q28. What is IDisposable and the using statement?

IDisposable has a Dispose method that releases unmanaged resources such as file handles and database connections. A using statement or declaration calls Dispose automatically, even if an exception occurs.

using var conn = new SqlConnection(connString);
conn.Open();
// connection is disposed at the end of the scope

Q29. What is the difference between Dispose and Finalize?

Dispose is called explicitly or by using to release resources immediately. A finaliser (~ClassName) is called by the garbage collector at an unknown time and should only be a safety net for unmanaged resources.

Q30. How do async and await work in C#?

An async method returns Task or Task<T>. await frees the current thread while waiting for I/O, such as a database or HTTP call, and resumes when the task completes. This improves scalability in web apps.

public async Task<Product?> GetAsync(int id)
{
    return await _db.Products.FindAsync(id);
}

Q31. What is the difference between Task and Thread?

A Thread is an operating-system thread that you manage directly. A Task is a higher-level unit of work scheduled on the thread pool, supports async/await, continuations and cancellation, and is preferred in modern code.

Q32. Why should you avoid async void?

async void methods cannot be awaited and their exceptions cannot be caught by the caller, which can crash the process. Use async Task, except for event handlers.

5. ASP.NET Core Interview Questions

Q33. What is ASP.NET Core?

ASP.NET Core is the cross-platform, high-performance framework for building web apps, REST APIs and real-time apps on .NET. It includes MVC, Razor Pages, minimal APIs, Blazor and SignalR.

Q34. What is middleware in ASP.NET Core?

Middleware components form a pipeline that handles each HTTP request and response in order, for example exception handling, HTTPS redirection, static files, routing, authentication, authorisation and endpoints. Order matters.

Q35. What is dependency injection in ASP.NET Core?

ASP.NET Core has a built-in DI container. You register services in Program.cs and receive them through constructors in controllers and other services.

Q36. What is the difference between Transient, Scoped and Singleton lifetimes?

Transient creates a new instance every time it is requested. Scoped creates one instance per HTTP request. Singleton creates one instance for the whole application lifetime.

builder.Services.AddTransient<IEmailSender, EmailSender>();
builder.Services.AddScoped<IOrderService, OrderService>();
builder.Services.AddSingleton<ICacheService, CacheService>();

Q37. How do you create a Web API controller?

Inherit from ControllerBase, add [ApiController] and [Route], and use attributes such as [HttpGet] and [HttpPost].

[ApiController]
[Route("api/[controller]")]
public class ProductsController : ControllerBase
{
    private readonly IProductService _service;
    public ProductsController(IProductService service) => _service = service;

    [HttpGet("{id}")]
    public async Task<ActionResult<Product>> Get(int id)
    {
        var p = await _service.GetAsync(id);
        return p is null ? NotFound() : Ok(p);
    }
}

Q38. What are minimal APIs?

Minimal APIs define HTTP endpoints directly in Program.cs with very little code, such as app.MapGet("/hello", () => "Hi"). They suit small services and microservices.

Q39. What is the difference between MVC and Razor Pages?

MVC separates models, views and controllers and suits larger apps and APIs. Razor Pages organises each page with its own handler code, which is simpler for page-focused applications.

Q40. What is model binding and validation?

Model binding maps data from routes, query strings, forms and JSON bodies to action parameters. Data annotations such as [Required] and [Range] validate it, and [ApiController] returns 400 Bad Request automatically for invalid models.

Q41. Where is configuration stored in ASP.NET Core?

In appsettings.json and appsettings.{Environment}.json, environment variables, user secrets in development, and command-line arguments, read through IConfiguration or the options pattern.

Q42. How do you implement authentication in ASP.NET Core?

Use ASP.NET Core Identity for user accounts, or JWT bearer authentication for APIs. Add app.UseAuthentication() and app.UseAuthorization() and protect endpoints with [Authorize].

6. Entity Framework Core Interview Questions

Q43. What is Entity Framework Core?

EF Core is Microsoft's ORM for .NET. It maps C# classes to database tables, translates LINQ queries into SQL, tracks changes, and supports SQL Server, PostgreSQL, MySQL, SQLite and more.

Q44. What is DbContext?

DbContext represents a session with the database. It holds DbSet<T> properties for tables, tracks changes and saves them with SaveChanges or SaveChangesAsync. It is registered as a scoped service in web apps.

Q45. What is the difference between code-first and database-first?

In code-first, you write C# entity classes and generate the database with migrations. In database-first, you scaffold entity classes from an existing database.

Q46. What are migrations?

Migrations record changes to your model as code, so the database schema can be updated step by step with dotnet ef migrations add and dotnet ef database update.

Q47. What is the difference between eager, lazy and explicit loading?

Eager loading loads related data in the same query with Include. Lazy loading loads it automatically when the navigation property is first accessed (needs proxies). Explicit loading loads it on demand with Entry(…).Collection(…).Load().

Q48. What is AsNoTracking?

AsNoTracking tells EF Core not to track returned entities, which makes read-only queries faster and uses less memory.

How to Prepare for a .NET Interview

  1. Master C# basics: value versus reference types, interfaces and LINQ are asked everywhere.
  2. Understand ASP.NET Core: middleware order, dependency injection and service lifetimes.
  3. Know async well: async/await, Task and why async void is risky.
  4. Build a Web API: with EF Core, JWT authentication and error handling.
  5. Learn Azure basics: many .NET roles involve deploying to Azure.

Next steps: revise SQL interview questions and Java interview questions for OOP practice, and see all subjects on our interview questions page.

Want a mentor for your preparation? We teach C#, .NET and back-end development through live online classes arranged around your free time, with mock interviews before your placement. Message us on WhatsApp or email engineersrworld@gmail.com.

More interview preparation: see all interview questions, including Python, SQL, SQL query, Java, JavaScript, React, C++, .NET, Spring Boot, Node.js, DSA, OOPs, DBMS, operating system, networking, machine learning, data science, AI, Excel, Power BI, DevOps, manual testing, Selenium, cyber security and HR.

Frequently Asked Questions

Which .NET topics are most asked for freshers?

OOP in C#, value versus reference types, abstract class versus interface, LINQ, async/await, ASP.NET Core middleware and dependency injection, service lifetimes and Entity Framework Core basics.

Should I learn .NET Framework or modern .NET?

Learn modern .NET (such as .NET 8 or later) with ASP.NET Core. .NET Framework knowledge helps only when maintaining older projects.

Is .NET a good career choice in India?

Yes. Many service companies, banks and product firms build on C# and ASP.NET Core, and Azure skills add further value.

How should I prepare for a .NET interview?

Build an ASP.NET Core Web API with EF Core, authentication and proper error handling, revise the concepts on this page, and practise writing C# and LINQ code by hand.

Scroll to Top