Skip to content

.NET Developer Interview Questions & Answers

40 questions for .NET Developer interviews — 30 easy, 9 medium, 1 hard.

About the .NET Developer role

A .NET developer builds and maintains back-end services and business applications using C# and ASP.NET Core. Daily work includes writing APIs, business logic and EF Core data access, fixing bugs, writing unit tests and joining code reviews. Freshers usually start on enhancement and support tasks in established projects before owning modules. Strong C#, OOP and SQL fundamentals matter most in interviews for this role.

C# and OOP LINQ queries ASP.NET Core basics SQL queries Git and unit testing
Solved for this roleStart practicing
3 QUESTIONS FREESign up to unlock the full question bank and track your progress.Unlock every question and answer, then continue practising company-wise and package-wise.
3 questions free Unlock the rest in seconds
01

What are boxing and unboxing?

Save to ▾
Show answer
Boxing converts a value type to object or an interface type by wrapping it in a heap object, for example object o = 42. Unboxing extracts the value back with an explicit cast, such as int n = (int)o. Both cost allocations and CPU time, and repeated boxing in loops increases garbage collection pressure. Generic collections like List<int> avoid boxing, which is one reason ArrayList is no longer used.
02

Explain First, FirstOrDefault, Single and SingleOrDefault.

Save to ▾
Show answer
First returns the first match and throws if none exists. FirstOrDefault returns the default value, null for classes, if none exists. Single expects exactly one match and throws if there are zero or more than one. SingleOrDefault returns default for zero but still throws for more than one. Use Single when duplicates would indicate a data bug, such as lookup by unique PAN number; otherwise FirstOrDefault is cheaper.
03

Write a SQL Server query to find the second highest salary.

Save to ▾
Show answer
-- using DENSE_RANK (handles ties) SELECT Salary FROM ( SELECT Salary, DENSE_RANK() OVER (ORDER BY Salary DESC) AS rnk FROM Employees ) t WHERE rnk = 2; -- using OFFSET SELECT DISTINCT Salary FROM Employees ORDER BY Salary DESC OFFSET 1 ROW FETCH NEXT 1 ROW ONLY; Change 2 to N for the Nth highest salary.
04

When should you use StringBuilder instead of string?

Save to ▾
Show answer
Strings in C# are immutable, so every concatenation creates a new string object and copies the old content. In a loop that appends thousands of times, this creates heavy allocations. StringBuilder keeps a resizable internal buffer and appends in place, so it is much faster for repeated changes. For two or three concatenations or interpolation in a single statement, a normal string is simpler and fine.
05

What is the difference between == and Equals() in C#?

Save to ▾
Show answer
For reference types, == by default checks reference equality, meaning both variables point to the same object, while Equals can be overridden to compare content. String overrides both, so == compares text. For value types, Equals compares field values. Records generate value-based equality automatically. When you override Equals, also override GetHashCode so objects behave correctly in dictionaries and hash sets.
06

Explain the ref, out and in parameter modifiers.

Save to ▾
Show answer
ref passes a variable by reference; it must be initialised before the call and the method can read and change it. out also passes by reference but need not be initialised, and the method must assign it before returning, as in int.TryParse. in passes by reference as read-only, which avoids copying large structs while preventing changes. Overusing ref and out makes code harder to read, so tuples are often cleaner.
07

What is the difference between concurrency and parallelism?

Save to ▾
Show answer
Concurrency means dealing with many tasks at once by interleaving them, for example a web server handling thousands of requests that mostly wait on I/O. Parallelism means doing many computations at the same instant on multiple cores, such as processing an image in four chunks. async/await gives concurrency; Parallel.For and PLINQ give parallelism. A program can be concurrent on a single core but parallel only with multiple cores.
08

You need to remove inactive users from a List<User> while looping through it with foreach, and you get an InvalidOperationException. How do you fix it?

Save to ▾
Show answer
foreach does not allow modifying the collection it is enumerating, so the enumerator throws. The simplest fix is users.RemoveAll(u => !u.IsActive), which is efficient and clear. Alternatives are looping backwards with a for loop and RemoveAt, or building a new filtered list with Where and ToList. For a dictionary, collect keys to remove first, then remove them after the loop.
09

What is the difference between a stored procedure and a user-defined function?

Save to ▾
Show answer
A stored procedure can perform inserts, updates and deletes, use transactions and TRY-CATCH, return multiple result sets and output parameters, and is called with EXEC. A function must return a value or table, cannot modify database state, and can be used inside SELECT, WHERE and JOIN. Scalar functions used row by row can hurt performance, although SQL Server 2019 and later can inline many of them.
10

Explain value types and reference types in C#.

Save to ▾
Show answer
Value types such as int, double, bool, enums and structs hold their data directly, and assigning one copies the value. Reference types such as classes, arrays, strings and delegates hold a reference to an object on the managed heap, so assigning copies only the reference. Changing a copied struct does not affect the original, but changing an object through a copied reference changes what both variables see.
11

Where do you see yourself in five years?

Save to ▾
Show answer
In five years I want to be a senior full stack engineer who can design a complete .NET system, from database and APIs to front end and cloud deployment, and guide newer developers. In the near term I want to master ASP.NET Core, EF Core and SQL Server performance, then grow into Azure and system design. I would like to grow inside one company where I can take on bigger modules over time.
12

What is the difference between JIT compilation and Native AOT in .NET?

Save to ▾
Show answer
With JIT, the app ships as IL and the runtime compiles methods to machine code when first called; tiered compilation later recompiles hot methods with better optimisation. Native AOT compiles everything ahead of time into a single native executable, giving very fast startup and lower memory, which suits containers and serverless. The trade-off is limited reflection and dynamic code generation, so some libraries need source generators to work.
13

Tell me about a time you had to learn a new C# or .NET feature quickly.

Save to ▾
Show answer
In my final-year project (Situation) our team needed async file uploads, but I only knew synchronous code. My task was to build the upload API within a week. I read the official async/await docs, built a small console demo, then refactored our controller to use async methods and IFormFile streaming. The result was uploads that no longer blocked requests, and I shared a short note with my team.
14

Write a switch expression using pattern matching to calculate shipping cost.

Save to ▾
Show answer
decimal Shipping(Order o) => o switch { { Total: >= 1000 } => 0m, { Country: "IN", Weight: < 2 } => 49m, { Country: "IN" } => 99m, { Weight: > 20 } => throw new ArgumentException("Too heavy"), _ => 499m }; Property and relational patterns replace long if-else chains, and the compiler warns if cases are not exhaustive.
15

What is the difference between a primary key and a unique key in SQL Server?

Save to ▾
Show answer
Both enforce uniqueness. A table can have only one primary key, it cannot contain NULLs, and by default SQL Server creates a clustered index for it. A table can have many unique constraints, each allowing a single NULL in SQL Server, and they create non-clustered indexes by default. Use the primary key for row identity, such as EmployeeId, and unique keys for business rules like a unique email or PAN.
16

Why do you want to work as a .NET full stack developer?

Save to ▾
Show answer
I enjoy building complete features, from database to screen, and .NET lets me do that with one strong, typed language on the back end. It is widely used by IT services firms, banks and product companies in India, so there are steady opportunities. I have built projects with ASP.NET Core and React, and I like that the platform is open source, cross-platform and keeps improving every year.
17

What is the difference between compile-time and runtime polymorphism?

Save to ▾
Show answer
Compile-time, or static, polymorphism is resolved by the compiler, mainly through method overloading and operator overloading, and through generics. Runtime, or dynamic, polymorphism is resolved when the program runs, through virtual methods and interfaces: a Shape reference may call Circle.Area or Square.Area depending on the actual object. Runtime polymorphism is what makes plugin designs and dependency injection possible.
18

What is the difference between a shallow copy and a deep copy?

OOP in C#Medium
Save to ▾
Show answer
A shallow copy duplicates the object but its reference fields still point to the same child objects; MemberwiseClone and record with-expressions do this. A deep copy duplicates the whole object graph, so changes to the copy never affect the original. Deep copies are usually written by hand or by serialising and deserialising. ICloneable is avoided because it does not say which kind of copy it returns.
19

What is the difference between a clustered and a non-clustered index?

Save to ▾
Show answer
A clustered index defines the physical order of the table's data, so the leaf level is the data itself, and a table can have only one. A non-clustered index is a separate structure with key values and a pointer back to the row, and a table can have many. Range queries on the clustered key are fast. Non-clustered indexes speed up searches on other columns but add cost to inserts and updates.
20

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

Save to ▾
Show answer
.NET Framework is the original Windows-only runtime, now in maintenance mode at version 4.8.1. .NET Core was the cross-platform, open-source rewrite. From .NET 5 onwards the name became just .NET, and it runs on Windows, Linux and macOS. In 2026, .NET 10 is the current LTS release. New projects should use modern .NET; Framework is kept only for legacy apps such as old Web Forms or WCF services.
21

Explain the different types of SQL joins.

Save to ▾
Show answer
INNER JOIN returns rows that match in both tables. LEFT JOIN returns all rows from the left table plus matches from the right, with NULLs where there is no match. RIGHT JOIN is the mirror. FULL OUTER JOIN returns all rows from both sides. CROSS JOIN returns every combination. A self join joins a table to itself, such as employees to their managers. LEFT JOIN with WHERE right.Id IS NULL finds unmatched rows.
22

What is LINQ and why is it useful?

Save to ▾
Show answer
LINQ, Language Integrated Query, lets you query collections, databases, XML and other sources with the same C# syntax using methods like Where, Select, OrderBy and GroupBy. Queries are type-checked at compile time and read close to the intent, for example orders.Where(o => o.Total > 500).OrderBy(o => o.Date). With EF Core, the same LINQ expression is translated into SQL, so you rarely write raw SQL strings.
23

What is the difference between method overloading and method overriding?

Save to ▾
Show answer
Overloading means several methods with the same name but different parameter lists in the same class, resolved at compile time, for example Add(int, int) and Add(double, double). Overriding means a derived class provides a new implementation of a virtual or abstract base method with the same signature, resolved at runtime based on the actual object type. Overloading is compile-time polymorphism; overriding is runtime polymorphism.
24

What is the difference between a static class and a singleton?

OOP in C#Medium
Save to ▾
Show answer
A static class cannot be instantiated, cannot implement interfaces and is initialised by the runtime; it suits stateless helpers like Math. A singleton is a normal class with exactly one instance, so it can implement interfaces, be passed as a parameter and be mocked in tests. In ASP.NET Core, you rarely write a singleton by hand; you register the class with AddSingleton and let the DI container manage its lifetime.
25

What is the difference between DELETE, TRUNCATE and DROP?

Save to ▾
Show answer
DELETE removes rows one by one, supports WHERE, fires triggers and is fully logged, so it is slower on big tables. TRUNCATE removes all rows by deallocating pages, is minimally logged, resets identity values and cannot have WHERE; it fails if foreign keys reference the table. DROP removes the whole table including structure, indexes and permissions. In SQL Server, both DELETE and TRUNCATE can be rolled back inside a transaction.
26

Show constructor chaining in C#.

Save to ▾
Show answer
public class Customer { public string Name { get; } public string City { get; } public Customer(string name) : this(name, "Unknown") { } public Customer(string name, string city) { Name = name; City = city; } } public class PremiumCustomer : Customer { public PremiumCustomer(string name) : base(name, "Delhi") { } } this() calls another constructor of the same class and base() calls the parent constructor, avoiding duplicated setup code.
27

Sort a list of students by marks descending, then by name ascending.

Save to ▾
Show answer
var ranked = students .OrderByDescending(s => s.Marks) .ThenBy(s => s.Name) .ToList(); // in-place alternative with a comparison students.Sort((a, b) => b.Marks != a.Marks ? b.Marks.CompareTo(a.Marks) : string.Compare(a.Name, b.Name, StringComparison.Ordinal)); OrderBy is stable and returns a new sequence; List.Sort sorts in place and is not stable.
28

Show the difference between ROW_NUMBER, RANK and DENSE_RANK with a query.

Save to ▾
Show answer
SELECT Name, Department, Salary, ROW_NUMBER() OVER (PARTITION BY Department ORDER BY Salary DESC) AS RowNum, RANK() OVER (PARTITION BY Department ORDER BY Salary DESC) AS Rnk, DENSE_RANK() OVER (PARTITION BY Department ORDER BY Salary DESC) AS DenseRnk FROM Employees; -- salaries 90, 90, 80 give -- ROW_NUMBER: 1, 2, 3 -- RANK: 1, 1, 3 -- DENSE_RANK: 1, 1, 2 PARTITION BY restarts numbering for each department.
29

What is the difference between var, dynamic and object?

Save to ▾
Show answer
var is implicitly typed: the compiler infers the real type at compile time, so it is fully type-safe. object is the base type of everything; you need casts to use specific members, and value types get boxed. dynamic skips compile-time checking and resolves members at runtime, so typos fail only when the code runs. Use var for readability, object rarely, and dynamic only for COM interop or truly dynamic data.
30

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

Save to ▾
Show answer
An abstract class can have fields, constructors, implemented and abstract members, and a class can inherit only one. An interface defines a contract; a class can implement many. Since C# 8, interfaces can have default method implementations but still no instance fields. Use an abstract class for shared state and base behaviour among closely related types, and interfaces for capabilities like IComparable or for dependency injection.
31

Write a C# method to reverse a string without using Array.Reverse or LINQ.

Save to ▾
Show answer
static string ReverseText(string input) { char[] chars = input.ToCharArray(); int left = 0, right = chars.Length - 1; while (left < right) { (chars[left], chars[right]) = (chars[right], chars[left]); left++; right--; } return new string(chars); } Two pointers swap from both ends, giving O(n) time and O(n) space for the char array.
32

Explain normalisation and the first three normal forms.

Save to ▾
Show answer
Normalisation organises tables to reduce redundancy and update anomalies. 1NF: each column holds atomic values and there are no repeating groups. 2NF: in 1NF and every non-key column depends on the whole primary key, not part of a composite key. 3NF: in 2NF and non-key columns do not depend on other non-key columns, for example City should not be stored with an order if it depends on the customer. Reporting databases may denormalise for speed.
33

Show encapsulation using properties, including init-only and validation.

Save to ▾
Show answer
public class BankAccount { public string AccountNo { get; init; } = ""; public decimal Balance { get; private set; } public void Deposit(decimal amount) { if (amount <= 0) throw new ArgumentOutOfRangeException(nameof(amount)); Balance += amount; } } var acc = new BankAccount { AccountNo = "SB1001" }; Balance can only change through Deposit, and AccountNo can be set only during object creation.
34

When would you choose an array, a List<T> or a LinkedList<T>?

Save to ▾
Show answer
An array has a fixed size and fastest index access, good when the count is known. List<T> wraps a resizable array, with O(1) index access and amortised O(1) add at the end, and is the default choice for most code. LinkedList<T> gives O(1) insert and remove at a known node but O(n) access by index and poor cache locality, so it is rarely the better option in practice.
35

What are your strengths and weaknesses as a developer?

Save to ▾
Show answer
My strength is that I go deep when debugging; I like reading execution plans and logs until I find the real cause, which has helped my team fix slow queries. A weakness was that I spent too long polishing code before asking for feedback. I now open small draft pull requests early and ask for review, which has made me faster and helped me learn from seniors sooner.
36

Why is Any() usually better than Count() > 0?

Save to ▾
Show answer
Any() stops as soon as it finds one element, so it is O(1) for most sources, and in EF Core it translates to an efficient SQL EXISTS. Count() may need to walk the entire sequence or run COUNT(*) on the table, which is wasteful just to check for existence. For List<T> or arrays, the Count or Length property is also fine because it is stored, but Any() expresses the intent clearly.
37

What are partial classes and partial methods?

Save to ▾
Show answer
A partial class splits one class definition across multiple files, and the compiler merges them. It is used heavily with generated code: designers, EF Core scaffolding and source generators write one part while you write the other, so regeneration does not erase your code. Partial methods declare a signature in one part and an optional implementation in another; since C# 9 they can have return types and access modifiers if implemented.
38

Show how to implement IDisposable and use the using statement.

Save to ▾
Show answer
public class FileLogger : IDisposable { private readonly StreamWriter _writer = new("log.txt"); public void Log(string msg) => _writer.WriteLine(msg); public void Dispose() => _writer.Dispose(); } // using declaration disposes at end of scope using var logger = new FileLogger(); logger.Log("Started"); Dispose releases unmanaged resources such as file handles and connections deterministically instead of waiting for the GC.
39

A report builder concatenates 50,000 rows into one string with += and takes several seconds. What do you change?

Save to ▾
Show answer
Each += creates a new string and copies everything built so far, so the cost grows quadratically. Replace it with a StringBuilder, ideally created with an estimated capacity, and call Append or AppendLine in the loop, then ToString once at the end. For very large output, write directly to a StreamWriter or the response stream instead of building the whole string in memory.
40

What is SQL injection and how do you prevent it in a .NET application?

Save to ▾
Show answer
SQL injection happens when user input is concatenated into SQL text, letting attackers change the query, for example entering ' OR 1=1 -- in a login box. Prevent it by always using parameters: SqlCommand with SqlParameter, EF Core LINQ, FromSql with interpolation, or Dapper parameters. Also use least-privilege database accounts, validate input and never show raw database errors to users. Stored procedures help only if they also avoid dynamic SQL concatenation.

Frequently asked questions

What does a .NET Developer do?

A .NET developer builds and maintains back-end services and business applications using C# and ASP.NET Core. Daily work includes writing APIs, business logic and EF Core data access, fixing bugs, writing unit tests and joining code reviews. Freshers usually start on enhancement and support tasks in established projects before owning modules. Strong C#, OOP and SQL fundamentals matter most in interviews for this role.

Which skills are tested in a .NET Developer interview?

Expect questions on C# and OOP, LINQ queries, ASP.NET Core basics, SQL queries, Git and unit testing. Most rounds also ask you to explain a project and solve one practical problem live.

How do I prepare for a .NET Developer interview?

Revise C# Fundamentals, OOP in C#, LINQ, Collections and Generics, SQL Server and T-SQL first using the topic sheets, practise the questions on this page aloud, then do one full mock interview to practise timing.