Best C# Interview Questions And Answers

If you want to hire a professional C# developer, you need to test their skills and knowledge to see whether the person corresponds to your demands. Once you have found the CV appropriate for the position, invite the candidate to the interview and define their proficiency level.

These C# programming interview questions may assist not only employers who try to choose the best C# developer but also people preparing for a job interview. It may help them to prepare for possible questions and repeat data on basic concepts.

Junior C# Developer Interview Questions


What is the .NET Assembly Manifest?

Assembly Manifest describes the relationship and dependencies of the components in the assembly and contains a reference to the resource and classes. It is stored in either a .exe or a .dll with Microsoft intermediate language (MSIL) code. Assembly Manifest renders the assembly self-describing, enumerates the assembly files and other assemblies on which it depends.


What are Boxing and Unboxing?

Boxing and Unboxing are used for type conversion, but the difference is that Boxing is done implicitly, while Unboxing has to be explicit by code. Boxing is the process of converting a value type data type to the object or to any interface data type which is implemented by this value type. Unboxing is used to extract the value type from the object or any implemented interface type.


What is the unchecked keyword?

C# provides checked and unchecked keywords to manage integral type exceptions. The unchecked keyword is used to suppress overflow-checking for integral-type arithmetic operations and conversions. It can produce results that may be truncated or wrong.


What is Managed or Unmanaged Code?

Managed Code is developed in the .NET framework and is performed by CLR with managed code execution. Moreover, any language written in .NET Framework is managed code.

Unmanaged Code is developed outside the .NET framework, and it accesses low-level functions of the operating system. The examples of unmanaged code are background compatibility with the code of VB, ASP, and COM.


What is namespace in C#?

A namespace keeps one set of names separate from another. The class names declared in one namespace do not conflict with the same class names declared in another.


    class SampleClass


        public void SampleMethod()



              "SampleMethod inside SampleNamespace");





What is MSIL in .NET?

MSIL means Microsoft Intermediate Language and is a CPU-independent set of instructions that can be efficiently converted to the native code. MSIL includes instructions for loading, storing, initializing, and calling methods on objects. 


What is the main difference between String and StringBuilder?

The string is immutable, meaning if you create a string object you cannot modify it, and it always creates a new object of string type in memory. StringBuilder is mutable, meaning that after creating a string builder object you can perform any operations like insert, replace or append. It updates the string in one place and doesn't create a new space in memory.


What is the entry point in the program, where and when it exists?

The entry point is the main method of a C# console or windows application. It is present in every executable application and is the place where the program control starts and ends. You can use only one entry point in any C# program.


Why do we use finally block in C#?

The finally block will be executed irrespective of exception. So, while executing the code, try block when an exception occurs, control is returned to catch block and at last, finally block will be executed. The finally block can keep closing connections to the database / releasing the file handlers.


What are OOP and its basic principles?

Object-oriented programming decomposes a problem into a number of entities called objects and then builds data and functions around these objects. It has four basic principles that include encapsulation, abstraction, inheritance, and polymorphism.

Mid C# Developer Interview Questions


What is Anonymous type in C#?

With anonymous types, it’s possible to create a new type without defining them. It is a way to define properties into a single object without having to define type explicitly. Type is generated by the compiler, and it is accessible only for the current block of code. The compiler infers the type of properties.

var anonymousData = new


     ForeName = "Jignesh",  

     SurName = "Trivedi"


Console.WriteLine("First Name : " + anonymousData.ForeName);


Can you explain SOLID principles?

SOLID is a mnemonic device for five design principles of object-oriented programs (OOP), resulting in readable, adaptable, and scalable code. It was promoted by Robert C Martin and is used across the object-oriented design spectrum. This abbreviation is deciphered as: 

  • Single-responsibility principle
  • Open-closed principle
  • Liskov substitution principle
  • Interface segregation principle
  • Dependency inversion principle


What is the difference between Thread and Task in .NET?

The thread represents an actual OS-level thread, with its own stack and kernel resources. The thread allows the highest degree of control so that it’s possible to Abort() or Suspend() or Resume() a thread. It should be mentioned that ThreadPool is a wrapper around a pool of threads maintained by the CLR.

The Task class from the Task Parallel Library offers the best of both worlds. Like the ThreadPool, a task does not create its OS thread. Instead, tasks are executed by a TaskScheduler; the default scheduler simply runs on the ThreadPool. Unlike the ThreadPool, Task also allows you to find out when it finishes, and with the help of the generic Task to return a result.


List different ASP.NET validators

ASP.NET has a set of validation controls that are used to validate HTML forms. There are six types of validators:

  • RequiredFieldValidator
  • CompareValidator
  • RangeValidator
  • RegularExpressionValidator
  • CustomValidator
  • ValidationSummary


What are lambda expressions in C#?

A lambda expression is an anonymous function that you can use to create delegates or expression tree types. Using lambda expressions, you can write local functions that can be passed as arguments or returned as the value of function calls. 

Here is an example of the lambda expression where x => x * x, specifying a parameter that's named x and returns the value of x squared, is assigned to a variable of a delegate type:

Func<int, int> square = x => x * x;


// Output:

// 25


What’s the difference between Server.Transfer and Response.Redirect.?

Server.Transfer and Response.Redirect both are used to transfer a user from one page to another. However, Response.Redirect() sends you to a new page, updates the address bar, and adds it to the Browser History. Server.Transfer() does not change the address bar so that it’s impossible to hit back. It’s used when a person doesn’t want the user to see where he is going.


What is the difference between ref and out keywords?

The ref keyword provides the data about the object that has been initialized before entering the function. On the other hand, out tells the compiler that the object will be initialized inside the function. Consider that ref is two-way, while out is out-only.


What is LINQ?

LINQ (Language Integrated Query) is a uniform query syntax in C# and VB.NET to retrieve data from different sources and formats. It is integrated into C# or VB to eliminate the mismatch between programming languages and databases, as well as providing a single querying interface for different types of data sources.


Explain the ASP.NET page life cycle in brief.

The ASP.NET life cycle is divided into Application Life Cycle and Page Life Cycle. The page life cycle phases include initialization, instantiation of the controls on the page, restoration and maintenance of the state, execution of the event handler codes, and page rendering. ASP.NET Application life cycle consists of the following stages: application start, object creation, HttpApplication creation, dispose of, application end.


What are the ASP.NET session state modes?

ASP.NET session state supports five different modes: 

Off - Used to disable sessions on the website.

InProc - Sessions are stored inside of the application's process on a web server. Depending on the IIS version used that could be aspnet_wp.exe or w3wp.exe.

StateServer - Sessions are stored using State Server windows service.

SQLServer - SQL Server database is used to store sessions' data

Custom - Manage session state using custom session state provider. Storage could be anything you implement in a provider.

Senior C# Developer Interview Questions


What is the difference between early binding and late binding in C#?

In Compile time polymorphism or Early Binding one uses multiple methods with the same name but different types of parameters or may be the number of parameters. Therefore, we can perform different tasks with the same method name in the same class, which is also known as Method overloading.

Run Time polymorphism or Late Binding allows us to use the same method names with the same signatures meaning the same type or the same number of parameters but not in the same. It’s caused by the fact that the compiler doesn't allow that at compile time.


How do you implement a generic action in WebAPI?

A Web API is an application programming interface, so it’s impossible to implement a generic action, as it needs to know the method signatures in advance.


Explain the difference between constants and read-only variables.

Constants are evaluated at compile time, while the read-only variables are evaluated at run time. Constants support only value-type variables (the only exception are strings), while read-only variables can hold reference-type variables. Constants should be used when the value is not changing during run time, and read-only variables are used mostly when their actual value is unknown before run time. Read-only variables can only be initialized at the time of declaration or in a constructor.


What is the difference between an Interface and an Abstract Class in .NET?

An interface declares solely properties, methods, and events with no access modifiers. All the declared members must be implemented.

An abstract class can declare fields and provide a partial implementation for functionality, and some abstract/virtual members that must be implemented by the inheriting entities.


What is the output of the short program below? Explain your answer.

Consider the problem:

class Program {

  static String location;

  static DateTime time;

  static void Main() {

    Console.WriteLine(location == null ? "location is null" : location);

    Console.WriteLine(time == null ? "time is null" : time.ToString());



The output will be:

location is null

1/1/0001 12:00:00 AM

Although both variables are uninitialized, String is a reference type and DateTime is a value type. As a value type, an uninitialized DateTime variable is set to a default value of midnight of 1/1/1 (yup, that’s the year 1 A.D.), not null.


What is GOD class, and why should it be avoided?

GOD classes are used for effective application breaking. They are the classes that keep track of a lot of information and have several responsibilities. One code change will most likely affect other parts of the class and therefore indirectly all other classes that use it. It can lead to an even bigger maintenance mess since new functionality is solely added to it.


When would you use the Duplex WCF service?

Duplex is used for callback pattern implementations. It’s possible to implement two options there is no data on the time of the event:

With polling, one can send requests every X minutes to check if an event happened. The server should either return event details (if it happened) or return a flag saying that you need to continue calling. Callback means that a client sends some form describing what the server should do if an event happens. The server remembers that data and makes a call from their side, performing the client function (initiates communication).

WCF duplex communications may require special network configuration because, in many cases, the network allows you to call external services but forbids them to call you back.


What is a delegate in .NET?

A delegate is similar to a function pointer, and it allows the programmer to encapsulate a reference to a method inside a delegate object. The delegate object can then be passed to code which can call the referenced method, without having to know at compile time which method will be invoked. In addition, one can take advantage of delegates to create custom events within a class.


Why do we use lock statement in C#?

The lock keyword ensures that one thread does not enter a critical section of code while another thread is in the critical section. If another thread tries to enter a locked code, it will wait, block, until the object is released. The lock keyword calls Enter at the start of the block, and Exit at the end of the block. 

private static readonly Object obj = new Object();

lock (obj)


    // critical section



Explain the following acronyms in .NET: IL, CIL, MSIL, CLI, and JIT.

IL stands for Intermediate Language that is a CPU-independent partially compiled code. In .NET, IL is called Common Intermediate Language (CIL), and in the early .NET days, it was called Microsoft Intermediate Language (MSIL). CLI means Common Language Infrastructure and is an open specification developed by Microsoft. JIT refers to just-in-time compilation that is a way of executing computer code that involves compilation during the execution of a program.

Hiring C# developers?
We have the people you are looking for!
Get in touch
Looking for vetted C# developers to join your team?

There are hundreds of battle-proven software development experts in our Talent Network.

Are you a C# developer looking for amazing projects? Join as a Talent