C# & .NET Interview Questions 2024 Edition
C# & .NET Interview Questions 2024 Edition
NET
Interview Questions
First Edition Handbook
LinkedIn
For free mock interview contact me at
While I can't guarantee that knowing all the answers will ensure you pass your interview, I can
promise that it will significantly boost your confidence in C# and .NET development.
1
Questions
1. Does .NET support multiple inheritance of interfaces?
Yes, .NET allows a class to implement multiple interfaces. This means a class can inherit
from multiple interface contracts, providing flexibility in defining behaviors.
6. Can the static method be called without instantiating the class where it is defined?
Yes, static methods belong to the class itself rather than an instance.
No, static methods should be called on the class rather than on an instance.
A virtual function is a method defined in a base class that derived classes can override.
2
11. What is the size limit of the Garbage Collector’s small object heap?
The size limit for the Garbage Collector’s (GC) small object heap is 85KB.
13. Where are stored the most recent objects? In which generation?
Yes if a certain condition is done. The answer to that is in the following question answer.
15. Is “using” the only way to perform a cleaning object from memory? Do you know the
pattern for doing garbage collection?
The “using” statement is not the only way. The Disposable pattern and implementation of
the IDisposable interface are also used to manage and clean up unmanaged resources.
< 85kB
SOH stands for Small Object Heap, and LOH stands for Large Object Heap.
18. If GC runs and deletes 1th generation, does it mean it also deletes 0th generation?
Yes, when the GC collects Generation 1, it also cleans up Generation 0 objects as part of
the process.
19. Which objects are cleaned? How does GC know which object should be deleted?
The two main methods of garbage collection are sweeping (removing unreachable
objects) and compacting (rearranging memory to reduce fragmentation).
3
21. What are the three phases of GC's way of working?
- Marking
- Relocating
- Compacting
22. Where are stored referenced types(classes, objects, constants)? On stack or the heap?
On the heap.
23. var car = new Car(“BMW”); Variable “car” is value or reference type?
“car” is a reference type. It holds a reference to the “Car” object on the heap.
25. Does “Heap” memory contain one “layer” for static variables?
No, static variables are stored in a separate area called the High-Level Object (HLO)
space, not in the heap.
26. Do you know some more reference types other than classes and objects?
28. What types of Garbage Collector exists? Hint: There are two of them.
- Server(Default in .NET)
- Workstation
29. Can you use the “using” statement if the class does not implement the “dispose” method?
No, the using statement requires the class to implement the IDisposable interface with a
Dispose method.
Yes, in .NET, Finalize is the term used for destructors, which are used to clean up
unmanaged resources before an object is collected by the GC.
4
31. What is method overloading?
Method overloading allows multiple methods with the same name but different signatures
(different parameters or return types) to be defined in the same class.
The GAC is a machine-wide cache that stores assemblies shared among multiple
applications on a computer, allowing for versioning and centralized management.
34. What is a keyword that we use to mark the method so it can be overridden?
Virtual.
A parameter is a variable defined in the method signature, while an argument is the actual
value passed to the method when it is called.
37. What does “step over” do while debugging? Does it skip the method?
“Step over” executes the current line of code, including method calls, without stepping
into the method's code. It does not skip the method but proceeds to the next line.
“throw ex” resets the call stack, losing the original error context, while “throw” preserves
the original stack trace, providing better debugging information.
The “void” keyword indicates that a method does not return any value.
5
41. What is the difference between the “Debug” and “Trace” classes?
The “Debug” class is used for logging and diagnostics only in debug builds, while the
“Trace” class is used for logging in both debug and release builds.
42. If a class does not inherit anything, what does it inherit by default?
System.Object
43. Does the “ref” parameter variable need to be initialized before or after calling the
method?
Tuples are a data structure that allows grouping multiple values of different types into a
single unit, providing a way to return multiple values from a method.
46. Is this considered good practice for naming a private field? -> _favoritePrimaryColor
Yes.
48. Does the number underline separator exist in C#? -> 1_419
The “800M” value represents the number 800 as a decimal type (decimal), where M
denotes a decimal literal.
6
51. What does “init;” do to a property?
The init; accessor allows the property to be set only during object initialization.
Yes.
No.
55. What you can use on strings and arrays to make them saved on stack memory?
You can use the Span<T> type and manual stack allocation with the “stackalloc” keyword.
56. Why would we use the “Span<T>” type and “stackalloc” while allocating an array or string?
Using Span<T> and stackalloc for temporary data can improve performance by avoiding
heap allocations and reducing garbage collection overhead.
Not anymore.
No, you cannot inject a scoped service into a singleton service because the singleton's
lifetime exceeds that of the scoped service, leading to potential issues with service
resolution.
7
61. Which types of service lifetimes exist?
- Singleton
- Scoped
- Transient
62. What types of .NET configurations exist?
- IConfiguration
- IOptions
- IOptionsSnapshot
- IOptionsMonitor
63. Does “asynchronous” resolve concurrency?
We can use it for the following types: int, float, and char.
No, the “sizeof” operator does not require an unsafe block for primitive types, but it does
for certain scenarios involving unmanaged types.
Serialization is the process of converting an object into a stream of bytes for storage or
transmission.
67. What type of comments exist rather than single and multi-line comments?
XML comments.
68. How C# code is compiled and executed. Define the stages of that process.
C# code is first compiled into Intermediate Language (IL) by the C# compiler. At runtime,
the Just-In-Time (JIT) compiler converts IL into native machine code for execution.
.exe or .dll
8
71. What’s the difference between “Array” and “ArrayList”?
- The array can not be null.
- The array needs to have a defined size.
- The array needs to have only one type of data stored in it.
72. What’s the difference between “String” and “StringBuilder”?
The string is immutable, meaning a new memory allocation is made for every modification.
16.
Occurs when two or more threads attempt to access and modify shared data
simultaneously, leading to conflicts and unpredictable behavior.
New Thread()
No.
79. What are the ways that the method can be overloaded?
- Different data types of parameters
- Different number of passed parameters
- Different order of passed parameters
80. What techniques of serialization are supported in .NET?
- JSON serialization
- XML & SOAP serialization
- Binary serialization
9
81. What do we use for binary serialization in .NET?
A monolith is a single, unified application where all components are tightly coupled.
Microservices are architecture where an application is broken down into smaller, loosely
coupled services that communicate over a network.
Immutable.
The “Singleton” pattern ensures that a class has only one instance in the application.
Allows adding new behavior to objects dynamically without altering their structure.
Design patterns are categorized into creational, structural, and behavioral patterns.
10
91. What is the difference between IEnumerable, IQueryable, List, and Array in .NET?
Use try, catch, and finally blocks to handle exceptions. try contains code that might throw
an exception, catch handles the exception, and finally executes code regardless of
whether an exception occurred.
Extension methods allow adding new methods to existing types without modifying their
source code. They are defined as static methods in static classes.
94. What is Entity Framework, and how does it differ from .NET?
Entity Framework (EF) is an ORM that provides an abstraction layer for database
interactions, whereas .NET involves writing raw SQL queries and managing data
connections manually.
An abstract class can provide default behavior and maintain state, while an interface
defines a contract without implementation. A class can implement multiple interfaces but
inherit from only one abstract class.
Task is used for asynchronous programming and provides higher-level abstractions for
managing concurrent operations, while Thread represents a lower-level thread of
execution.
11
98. How do you implement logging in a .NET application?
Logging can be implemented using built-in frameworks like ILogger in ASP.NET Core or
third-party libraries such as NLog or Serilog.
Attributes are metadata added to code elements (classes, methods, properties) that
provide additional information and can be retrieved using reflection.
___________________________________________________________________________
___________________________________________________________________________
Whats next?
I have a document that contains 250+ interview code questions called “Cracking the C#
.NET technical interview easy way”.
And that’s not all! If you want to do an online live interview with me 1 on 1 you can contact
me at [email protected].
___________________________________________________________________________
12
Useful links
13