C# and .NET Interview Questions: Fundamentals and OOP

Dot NET Programming 20 min min read Updated: Nov 16, 2026 Intermediate
C# and .NET Interview Questions: Fundamentals and OOP
Intermediate Topic 1 of 3

Practice answering each question out loud in your own words. Short, clear answers with a tiny example impress interviewers most.

1. What is the difference between .NET, the CLR and C#?

C# is the programming language. .NET is the platform with the runtime, libraries and tools. The CLR is the runtime that executes your compiled code (IL) with a JIT compiler, garbage collector and type safety.

2. Value types vs reference types?

Value typeReference type
Examplesint, bool, struct, enumclass, string, arrays, delegate
Copy behaviorCopies the valueCopies the reference (same object)
Typical storageStack or inside the containing objectHeap object, variable holds a reference
DefaultZero/falsenull
csharp int a = 5; int b = a; b = 10; // a is still 5 var p1 = new Person { Name = "Ana" }; var p2 = p1; p2.Name = "Bob"; // p1.Name is now "Bob" too

3. Is string a value type? Why is it immutable?

string is a reference type that behaves like a value because it is immutable: operations create a new string. Immutability makes strings thread-safe and safe as dictionary keys. Use StringBuilder when you build text in a loop.

4. What are boxing and unboxing?

csharp int x = 42; object o = x; // boxing: value copied into a heap object int y = (int)o; // unboxing

Both cost memory and time. Generics (List<int>) avoid boxing.

5. == vs Equals() vs ReferenceEquals?

  • == compares values for built-in types and strings, and references for classes unless overloaded
  • Equals() compares by value if overridden
  • ReferenceEquals always checks if two variables point to the same object
  • Records compare by value automatically

6. const vs readonly vs static readonly?

KeywordSet whenNotes
constCompile timeOnly simple types, baked into callers
readonlyDeclaration or constructorPer instance
static readonlyStatic constructor/declarationOne shared value, can be a complex object

7. ref, out and in?

ref passes a variable by reference (must be initialized). out must be assigned by the method and is used to return extra values. in passes by reference read-only, useful for large structs.

8. Class vs struct?

classstruct
TypeReferenceValue
InheritanceYesNo (interfaces only)
Best forMost objectsSmall, immutable data (about 16 bytes or less)

9. Abstract class vs interface?

Abstract classInterface
State (fields)YesNo instance fields
ConstructorsYesNo
InheritanceOne base classA class can implement many
Use whenShared base code for related typesA capability or contract

Interfaces can have default implementations since C# 8, but they remain contracts first.

10. virtual, override, new and sealed

csharp class Animal { public virtual string Speak() => "..."; } class Dog : Animal { public override string Speak() => "Woof"; } // replaces behavior (polymorphism) class Cat : Animal { public new string Speak() => "Meow"; } // hides: depends on variable type! sealed class Puppy : Dog { } // cannot be inherited

11. What are the four OOP pillars?

  • Encapsulation: hide data, expose safe members
  • Abstraction: show what, hide how
  • Inheritance: reuse and extend a base type
  • Polymorphism: same call, different behavior

12. Property vs field?

A field stores data. A property controls access with get and set, allows validation and can be changed later without breaking callers. Expose properties, not public fields.

13. What is a record and when do you use it?

A record is a reference type (or record struct) with value-based equality, with expressions and a built-in ToString. It is ideal for DTOs and immutable data.

csharp public record Point(int X, int Y); var a = new Point(1, 2); var b = a with { Y = 5 }; Console.WriteLine(a == new Point(1, 2)); // True

14. Nullable reference types?

With <Nullable>enable</Nullable> the compiler warns when a non-nullable reference might be null. string? means null is allowed. It does not change runtime behavior, it catches mistakes at compile time.

15. What is garbage collection?

The GC automatically frees memory of objects that are no longer reachable. It uses generations (0, 1, 2) so short-lived objects are cleaned cheaply. It does not close files or connections: use IDisposable and using.

16. IEnumerable vs IQueryable vs List?

  • IEnumerable<T>: in-memory iteration, deferred execution
  • IQueryable<T>: builds an expression tree translated to SQL by EF Core
  • List<T>: a concrete collection with data already in memory

17. What is async/await?

It lets a method wait for I/O (database, HTTP) without blocking a thread. The method returns a Task and continues when the work finishes. Avoid .Result and .Wait() because they can deadlock or waste threads.

18. Task.WhenAll vs Task.WhenAny

WhenAll completes when all tasks complete. WhenAny completes when the first completes (for example a timeout race).

19. What are generics and constraints?

csharp T Max<T>(T a, T b) where T : IComparable<T> => a.CompareTo(b) >= 0 ? a : b;

Generics give type safety and reuse without boxing. Constraints (where) say what a type argument must support.

20. Explain SOLID briefly

LetterMeaning
SA class should have one reason to change
OOpen for extension, closed for modification
LSubtypes must work wherever the base type is expected
IMany small interfaces beat one large interface
DDepend on abstractions, not concrete classes

Conclusion

Know the core ideas and give a small example for each: types, memory, OOP, records, async and SOLID. Understanding beats memorizing.

Quick Summary: Value vs reference, boxing, abstract vs interface, record, GC, async, SOLID.

Get Newsletter

Subscibe to our newsletter and we will notify you about the newest updates on Edugators