C# interview questions
As of September 2024, the current versions of C#, .NET Core, and .NET are as follows:
-
C# Version: C# 12 is the latest stable release. It introduces several new features, including primary constructors for classes and structs, collection expressions,
ref readonly
parameters, and more. C# 12 is compatible with .NET 8【8†source】. -
.NET Core Version: .NET Core has evolved into the broader .NET ecosystem, with the current version being .NET 8 (LTS). The latest release for .NET 8 is version 8.0.8, with long-term support ending in November 2026【9†source】【10†source】.
-
.NET Version: The latest .NET release is .NET 9, currently available as a release candidate (9.0.0-rc.1). The official release is expected in November 2024【8†source】【9†source】.
- Explain the difference between .NET and C#?
- .NET Framework vs .NET Core vs .NET 5.0
- What is IL (Intermediate Language) Code?
- What is the use of JIT (Just In Time compiler)?
- Is it possible to view IL code?
- What is the benefit of compiling into IL code?
- Does .NET support multiple programming languages?
- What is CLR (Common Language Runtime)?
- What is managed and unmanaged code?
- Explain the importance of the Garbage Collector?
- Can the garbage collector claim unmanaged objects?
- What is the importance of CTS?
- Explain CLS (Common Language Specification)?
- Difference between Stack vs Heap?
- What are Value types & Reference types?
- Explain boxing and unboxing?
- What are the consequences of boxing and unboxing?
- Explain casting, implicit casting, and explicit casting?
- What can happen during explicit casting?
- Differentiate between Array and ArrayList?
- Whose performance is better, Array or ArrayList?
- What are generic collections?
- What are threads (Multithreading)?
- How are threads different from TPL (Task Parallel Library)?
- How do we handle exceptions in C# (try/catch)?
- What is the need for the ‘finally’ block?
- Why do we need the ‘out’ keyword?
- What is the need for Delegates?
- What are events?
- What’s the difference between an Abstract class and an Interface?
- What is a Delegate and how to create a Delegate?
- Where have you used Delegates?
- What is a Multicast Delegate?
- What is an Event?
- How to Create an Event?
- Delegate vs Events.
- Why do we need OOP (Object-Oriented Programming)?
- What are the important pillars of OOPs?
- What is a class and object?
- Abstraction vs Encapsulation?
- Explain Inheritance?
- Explain the ‘virtual’ keyword?
- What is overriding?
- Explain overloading?
- Overloading vs Overriding?
- Explain static vs dynamic polymorphism?
- Explain operator overloading?
- Why do we need Abstract classes?
- Are Abstract methods virtual?
- Can we create an instance of Abstract classes?
- Is it compulsory to implement Abstract methods?
- Why simple base class can replace an Abstract class?
- Explain interfaces and why do we need them?
- Can we write logic in an interface?
- Can we define methods as private in an interface?
- If I want to change an interface, what’s the best practice?
- Explain multiple inheritance in Interface?
- Explain Interface Segregation Principle (ISP)?
- Can we create an instance of an interface?
- Can we do multiple inheritance with Abstract classes?
- Abstract Class vs Interface?
- Why do we need constructors?
- In parent-child inheritance, which constructor fires first?
- How are initializers executed?
- How are static constructors executed in parent-child inheritance?
- When does the static constructor fire?
- What is shadowing?
- Explain method hiding?
- Shadowing vs Overriding?
- When do we need Shadowing?
- Explain Sealed Classes?
- Can we create an instance of sealed classes?
- What are nested classes and when to use them?
- Can a nested class access outer class variables?
- Can we have public/protected access modifiers in nested classes?
- Explain Partial classes?
- In what scenarios do we use partial classes?
- What is SOLID?
- What is the full form of SOLID?
- What is the goal of SOLID?
- Explain SRP (Single Responsibility Principle) with an example?
- What is the benefit of SRP?
- Explain OCP (Open-Closed Principle) with an example?
- What is the benefit of OCP?
- Can you explain Liskov Substitution Principle and its violation?
- How can we fix Liskov Substitution Principle violation?
- Explain Dependency Injection with an example?
- Explain IoC (Inversion of Control)?
- What are design patterns?
- What are the different types of design patterns?
- Explain Structural, Behavioral, and Creational design patterns?
- Explain the Singleton Pattern and its use?
- How did you implement the Singleton pattern?
- Can we use a static class instead of using a private constructor in a Singleton?
- Static vs Singleton pattern?
- How did you implement thread safety in Singleton?
- What is double-null check in Singleton?
- Can the Singleton pattern code be made easy with the Lazy keyword?
- Can we get rid of double-null check code in Singleton?
- What is composition?
- Explain Aggregation.
- Explain Association.
- Differentiate between Composition vs Aggregation vs Association.
- UML Symbols for Composition, Aggregation, and Association.
- Explain Stack and Heap.
- Where are Stack and Heap stored?
- What goes on Stack and what goes on Heap?
- How is the Stack memory address arranged?
- How is Stack memory deallocated (LIFO or FIFO)?
- How are primitive types and objects stored in memory?
- Can primitive data types be stored in Heap?
- Explain value types and reference types.
- Explain ‘ByVal’ and ‘ByRef’.
- Differentiate between copy by value and copy by reference.
- What is boxing and unboxing?
- Is boxing/unboxing good or bad?
- Can we avoid boxing and unboxing?
- What effect does boxing and unboxing have on performance?
- Are strings allocated on Stack or Heap?
- How many Stacks and Heaps are created for an application?
- How are Stack and Heap memory deallocated?
- Who clears the Heap memory?
- Where is a structure allocated: Stack or Heap?
- Are structures copied by value or by reference?
- Can structures get created on Heap?
- Explain the Garbage Collector (GC).
- How does the Garbage Collector know when to clean objects?
- Is there a way to view Heap memory?
- Does the Garbage Collector clean primitive types?
- Managed vs Unmanaged code/objects/resources?
- Can the Garbage Collector clean unmanaged code?
- Explain Generations in the Garbage Collector.
- What is GC0, GC1, and GC2?
- Why do we need Generations in the Garbage Collector?
- Which is the best place to clean unmanaged objects?
- How does the Garbage Collector behave when we have a destructor?
- What do you think about an empty destructor?
- Explain the Dispose Pattern.
- Finalize vs Destructor.
- What is the use of the ‘using’ keyword?
- Can you force Garbage Collection?
- Is it a good practice to force Garbage Collection?
- How can we detect memory issues?
- How can we know the exact source of memory issues?
- What is a memory leak?
- Can a .NET application have memory leaks even with the Garbage Collector?
- How to detect memory leaks in .NET applications?
- Explain weak and strong references.
- When will you use weak references?
- What are design patterns?
- What are the different types of design patterns?
- Explain Structural, Behavioral, and Creational design patterns.
- Explain the Singleton Pattern and its use.
- How did you implement the Singleton pattern?
- Can we use a static class instead of a Singleton with a private constructor?
- Static vs Singleton pattern.
- How did you implement thread safety in Singleton?
- What is double-null check in Singleton?
- Can Singleton pattern code be made easier with the Lazy keyword?
- Can we eliminate double-null check code?
Leave a Reply