C# Interview Questions For experienced

1. What is C#?
Answer: C# is the best language for writing Microsoft .NET applications. C# provides the rapid application development found in Visual Basic with the power of C++. Its syntax is similar to C++ syntax and meets 100% of the requirements of OOPs like the following:

  • Abstraction
  • Encapsulation
  • Polymorphism
  • Inheritance

To know more about C# Language read the following article:
Introduction to C#
The latest version of C# is C# 6.0 with lots of new features.

2. Differentiate between Static class and Singleton instance?
Answer: Static Class Singleton instance
A static class cannot implement an interface A singleton instance, can implement an interface
Cloning of objects is not possible Cloning of objects is possible
Stores in stack Stores in heap
Generally initialized when it is first loaded Can be initialized lazily or asynchronously
The Singleton pattern is considered an anti-pattern because they are not easy to handle with unit test and their instantiation cannot be controlled, Memory allocated to a Singleton cannot be freed. In the multithreaded environment, access to the singleton object should to be guarded in the multithreaded environment, and it is hard to test as it promotes tight coupling between classes.

3. What are the Access Modifiers in C#?
Answer: Different Access Modifier is – Public, Private, Protected, Internal, Protected Internal
Public – When a method or attribute is defined as Public, it can be accessed from any code in the project. For example, in the above Class “Employee” getName() and setName() are public.
Private – When a method or attribute is defined as Private, It can be accessed by any code within the containing class only. For example, in the above Class “Employee” attributes name and salary can be accessed within the Class Employee Only. If an attribute or class is defined without access modifiers, it’s default access modifier will be private.
Protected – When attribute and methods are defined as protected, it can be accessed by any method in the inherited classes and any method within the same class. The protected access modifier cannot be applied to classes and interfaces. Methods and fields in a interface can’t be declared protected.
Internal – If an attribute or method is defined as Internal, access is restricted to classes within the current project assembly.
Protected Internal – If an attribute or method is defined as Protected Internal, access is restricted to classes within the current project assembly and types derived from the containing class.

4. How are methods overloaded?
Answer: Methods are overloaded via different signatures (number of parameters and types). Thus, you can overload a method by having different data types, different number of parameters, or a different order of parameters.

5. Differentiate between Object pooling and Connection pooling in C#?
Answer: The object pool implementation increases the size of the pool to the maximum. Instead of throwing an exception, when the maximum is reached,it makes the client wait until an object is returned to the pool and then gives the newly returned object to the waiting client.

The connection pool implementation does not require, a maximum size parameter – it will keep creating new connections as and when required in order to meet demand (eventually it will hit some system limit resulting in the failure in some way that isn’t specified.

6. What are namespaces, and how they are used?
Answer: Namespaces are used to organize classes within the .NET Framework. They dictate the logical structure of the code. They are analogous to Java packages, with the key difference being Java packages define the physical layout of source files (directory structure) while .NET namespaces do not. However, many developers follow this approach and organize their C# source files in directories that correlate with namespaces. The .NET Framework has namespaces defined for its many classes, such as System.Xml—these are utilized via the using statement. Namespaces are assigned to classes via the namespace keyword.

7. Why to use “finally” block in C#?
“Finally” block will be executed irrespective of exception. So while executing the code in try block when exception is occurred, control is returned to catch block and at last “finally” block will be executed. So the closing connection to database / releasing the file handlers can be kept in “finally” block.

8. What is the difference between “finalize” and “finally” methods in C#?
Finalize – This method is used for garbage collection. So before destroying an object this method is called as part of clean up activity.
Finally – This method is used for executing the code irrespective of exception occurred or not.

9. What are the differences between a Class and a Struct?
Given below are the differences between a Class and a Struct:
Class Struct
Supports Inheritance Does not support Inheritance
Class is Pass by reference (reference type) Struct is Pass by Copy (Value type)
Members are private by default Members are public by default
Good for larger complex objects Good for Small isolated models
Can use waste collector for memory management Cannot use Garbage collector and hence no Memory management.

10. What is the difference between Virtual method and Abstract method?
Answer: A Virtual method must always have a default implementation. However, it can be overridden in the derived class, though not mandatory. It can be overridden using override keyword.

An Abstract method does not have an implementation. It resides in the abstract class. It is mandatory that the derived class implements the abstract method. An override keyword is not necessary here though it can be used. (.net Training Online)

11. What is a Race Condition?
Answer: A Race condition occurs when two threads access the same resource and are trying to change it at the same time. The thread which will be able to access the resource first cannot be predicted.
If we have two threads, T1 and T2, and they are trying to access a shared resource called X. And if both the threads try to write a value to X, the last value written to X will be saved.

12. What is Thread Pooling?
Answer: A Thread pool is a collection of threads. These threads can be used to perform tasks without disturbing the primary thread. Once the thread completes the task, the thread returns to the pool.
System.Threading.ThreadPool namespace has classes which manage the threads in the pool and its operations.
System.Threading.ThreadPool.QueueUserWorkItem(new System.Threading.WaitCallback(SomeTask));
The above line queues a task. SomeTask methods should have a parameter of type Object.

13. What are the types of Serialization?
The different types of Serialization are: XML serialization, SOAP, and Binary.
XML serialization – It serializes all the public properties to the XML document. Since the data is in XML format, it can be easily read and manipulated in various formats. The classes reside in System.sml.Serialization.
SOAP – Classes reside in System.Runtime.Serialization. Similar to XML but produces a complete SOAP compliant envelope which can be used by any system that understands SOAP.
Binary Serialization – Allows any code to be converted to its binary form. Can serialize and restore public and non-public properties. It is faster and occupies less space.

14. Name any three ways to pass parameters to a method in C#?

Value parameters: The passing of a parameter to a method by value. A new storage location for the value parameter is created while using the method. The argument does not get affected when changes are made to the value parameter by using this method.
Reference parameters: Here instead of creating a new storage location for the parameter, the method accesses the memory location of the argument and passes it as a parameter. Passing of a parameter to a method by reference can be achieved by using the ref keyword. The argument gets affected when changes are made to the value parameter by using this method.
Output parameters: In this method the out keyword allows a method to return two values from a function. It is similar to passing a reference parameter, but in this case, data is being transferred out.

15. What happens if the inherited interfaces have conflicting method names?
Answer: If we implement multipole interface in the same class with conflict method name so we don’t need to define all or in other words we can say if we have conflict methods in same class so we can’t implement their body independently in the same class coz of same name and same signature so we have to use interface name before method name to remove this method confiscation let’s see an example:
interface testInterface1 {
void Show();
interface testInterface2 {
void Show();
class Abc: testInterface1,
testInterface2 {
void testInterface1.Show() {
Console.WriteLine(“For testInterface1 !!”);
void testInterface2.Show() {
Console.WriteLine(“For testInterface2 !!”);

Now see how to use those in a class:
class Program {
static void Main(string[] args) {
testInterface1 obj1 = new Abc();
testInterface1 obj2 = new Abc();

16. What is multicast delegate in c# ?
Answer: Delegate can invoke only one method reference has been encapsulated into the delegate.it is possible for certain delegate to hold and invoke multiple methods such delegate called multicast delegates.multicast delegates also know as combinable delegates, must satisfy the following conditions:

The return type of the delegate must be void. None of the parameters of the delegate type can be delegate type can be declared as output parameters using out keywords.
Multicast delegate instance that created by combining two delegates, the invocation list is formed by concatenating the invocation list of two operand of the addition operation. Delegates are invoked in the order they are added.
Implement Multicast Delegates Example:
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
delegate void MDelegate();
class DM {
static public void Display() {
static public void print() {
class MTest {
public static void Main() {
MDelegate m1 = new MDelegate(DM.Display);
MDelegate m2 = new MDelegate(DM.print);
MDelegate m3 = m1 + m2;
MDelegate m4 = m2 + m1;
MDelegate m5 = m3 – m2;

Use following link to with more details:
How to create implement multicast Delegates in C#
Delegate in C#

17. What is the difference between a struct and a class?
Answer: Structs cannot be inherited. Structs are passed by value and not by reference. Structs are stored on the stack not the heap. The result is better performance with Structs.

18. What is a singleton?
Answer: A singleton is a design pattern used when only one instance of an object is created and shared; that is, it only allows one instance of itself to be created. Any attempt to create another instance simply returns a reference to the first one. Singleton classes are created by defining all class constructors as private. In addition, a private static member is created as the same type of the class, along with a public static member that returns an instance of the class. Here is a basic example:

public class SingletonExample {
private static SingletonExample _Instance;
private SingletonExample () { }
public static SingletonExample GetInstance() {
if (_Instance == null) {
_Instance = new SingletonExample ();

return _Instance;

19. What is boxing?
Answer: Boxing is the process of explicitly converting a value type into a corresponding reference type. Basically, this involves creating a new object on the heap and placing the value there. Reversing the process is just as easy with unboxing, which converts the value in an object reference on the heap into a corresponding value type on the stack. The unboxing process begins by verifying that the recipient value type is equivalent to the boxed type. If the operation is permitted, the value is copied to the stack.

20. What is enum in C#?
Answer: enumerator list. The enum keyword is used to declare an enumeration. It is a primitive data type, which is user defined. 
An enum type can be an integer (float, int, byte, double etc.). But if you used beside int it has to be cast.
An enum is used to create numeric constants in .NET framework. All the members of enum are of enum type. Their must be a numeric value for each enum type.
The default underlying type of the enumeration element is int. By default, the first enumerator has the value 0, and the value of each successive enumerator is increased by 1.
enum Dow {Sat, Sun, Mon, Tue, Wed, Thu, Fri};
Some points about enum
Enums are enumerated data type in c#.
Enums are not for end-user, they are meant for developers.
Enums are strongly typed constant. They are strongly typed, i.e. an enum of one type may not be implicitly assigned to an enum of another type even though the underlying value of their members are the same.
Enumerations (enums) make your code much more readable and understandable.
Enum values are fixed. Enum can be displayed as a string and processed as an integer.
The default type is int, and the approved types are byte, sbyte, short, ushort, uint, long, and ulong.
Every enum type automatically derives from System.Enum and thus we can use System.Enum methods on enums.
Enums are value types and are created on the stack and not on the heap.
For more details follow the link:
Enums in C#
Enumeration in C#

21. Different Ways of Method can be overloaded?
Answer: Method overloading is a way to achieve compile time Polymorphism where we can use a method with the same name but different signature, Method overloading is done at compile time and we have multiple way to do that but in all way method name should be same.

Number of parameter can be different.
Types of parameter can be different.
Order of parameters can be different.
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace Hello_Word {
class overloding {
public static void Main() {
Console.WriteLine(volume(2.5F, 8));
Console.WriteLine(volume(100L, 75, 15));

static int volume(int x) {
return (x * x * x);

static double volume(float r, int h) {
return (3.14 * r * r * h);

static long volume(long l, int b, int h) {
return (l * b * h);
Note: If we have a method that have two parameter object type and have a same name method with two integer parameter so when we call that method with int value so it’ll call that method have integer parameter instead of object type parameters method.

22. Explain Hash table in C# ?
Answer: A Hashtable is a collection that stores (Keys, Values) pairs. Here, the Keys are used to find the storage location and is immutable and cannot have duplicate entries in the Hashtable. The .Net Framework has provided a Hash Table class that contains all the functionality required to implement a hash table without any additional development. The hash table is a general-purpose dictionary collection. Each item within the collection is a DictionaryEntry object with two properties: a key object and a value object. These are known as Key/Value. When items are added to a hash table, a hash code is generated automatically. This code is hidden from the developer. All access to the table’s values is achieved using the key object for identification. As the items in the collection are sorted according to the hidden hash code, the items should be considered to be randomly ordered.
The Hashtable Collection
The Base Class libraries offers a Hashtable Class that is defined in the System.Collections namespace, so you don’t have to code your own hash tables. It processes each key of the hash that you add every time and then uses the hash code to look up the element very quickly. The capacity of a hash table is the number of elements the hash table can hold. As elements are added to a hash table, the capacity is automatically increased as required through reallocation. It is an older .Net Framework type.
Declaring a Hashtable
The Hashtable class is generally found in the namespace called System.Collections. So to execute any of the examples, we have to add using System.Collections; to the source code. The declaration for the Hashtable is:
Hashtable HT = new Hashtable ().

23. What are Async and Await?
Answer: Async and Await keywords are used to create asynchronous methods in C.
Asynchronous programming means that the process runs independently of main or other processes.
Usage of Async and Await is as shown below:
Async Keyword
Async keyword is used for the method declaration.
The count is of a task of type int which calls the method CalculateCount().
Calculatecount() starts execution and calculates something.
Independent work is done on my thread and then await count statement is reached.
If the Calculatecount is not finished, myMethod will return to its calling method, thus the main thread doesn’t get blocked.
If the Calculatecount is already finished, then we have the result available when the control reaches await count. So the next step will continue in the same thread. However, it is not the situation in the above case where Delay of 1 second is involved.

24. What is a class?
Answer: A class is the generic definition of what an object is. A Class describes all the attributes of the object, as well as the methods that implement the behavior of the member object. In other words, class is a template of an object. For ease of understanding a class, we will look at an example. In the class Employee given below, Name and Salary are the attributes of the class Person. The Setter and Getter methods are used to store and fetch data from the variable.

public class Employee

private String name;
private String Salary;
public String getName()

return name;

public void setName(String name)

this.name = name;

public String getSalary ()

return Salary;

public void setSalary (String Salary)

this. Salary = Salary;

25. What are the main reasons to use C# language?
These are top reasons to use C# language:

  • Easy to learn
  • General-purpose and object-oriented
  • programming language
  • Component oriented
  • Structured language
  • Can be compiled on a variety of computer platforms
  • Produces efficient programs
    Part of .net framework

26. What is the difference between public, static and void?
You can access public declared variables anywhere in the application.
Static declared variables are globally accessible without creating an instance of the class.
Void is a type modifier that specifies that the method doesn’t return any value.

27. What is Polymorphism in C#?
The ability of a programming language to process objects in different ways depending on their data type or class is known as Polymorphism. There are two types of polymorphism
Compile time polymorphism. Best example is Overloading
Runtime polymorphism. Best example is Overriding.

28. So what makes your code really object-oriented #?
Answer: In order to understand this, we must first analyze what benefits we can derive from OO. In order to do this, we must clearly understand its foundation.

So given that C# is at its core object-oriented, most interviewers might be tempted to ask the following question:

29. What is the this Pointer?
Answer: The this pointer is silently passed with a call to an instance-level function, which then operates on an object (instance of a class).
Basically, this core mechanism makes it possible to bring operations close to data. It also eliminates the need to have global functions and it gives data structures the intrinsic ability to perform operations on its data.
So, having said this, if we now raise the following question:

30. What is the OO fundamental idea using C# that allows a data structure to perform operations on its own data?
Answer: Pretty obvious. The humble this pointer.
Notice that despite this being a mind-bending idea, we can already start to appreciate the bigger picture for which C# was designed.
The this pointer is basically a way for a data structure (object) to be able to access methods that allow itself to perform operations on its own data. It is a way to manage state within a data structure.
Now let’s talk a bit about the other core concept that takes this to the next level.

31. What is an Object Pool in .Net?
Answer: Object Pooling is something that tries to keep a pool of objects in memory to be reused later and hence it will reduce the load of object creation to a great extent. This article will try to explain this in detail. The example is for an Employee object, but you can make it general by using the Object base class.

32. Which are the access modifiers available in C#?
Following are the access modifiers generally used for accessibility:
Public: If you define an attribute or method as public, it can be accessed from any code of the project.
Private: A private defined attribute or method can be accessed by any code within the containing class only.
Protected: If you define the method or attribute as protected it can be accessed by any method in the inherited classes and any method within the same class.
Internal: If you define an attribute or a method as internal, it is restricted to classes within the current position assembly.
Protected internal: If you define an attribute or method as protected internal, access is restricted to classes within the current project assembly or types derived from the containing class.

33. What is Data Encapsulation?
Answer: Data Encapsulation is defined as the process of hiding the important fields from the end-user. In the above example, we had used getters and setters to set value for MinSalary. The idea behind this is that, private field “minimumSalary” is an important part of our classes. So if we give a third party code to have complete control over the field without any validation, it can adversely affect the functionality. This is in line with the OOPS Concept that an external user should know about what an object does. How it does it, should be decided by the program. So if a user set a negative value for MinSalary, we can put a validation in the set method to avoid negative values as shown below. (Interview Questions and Answers)

34. Explain Inheritance in C#?
Answer: In object-oriented programming (OOP), inheritance is a way to reuse code of existing objects. In inheritance, there will be two classes – base class and derived classes. A class can inherit attributes and methods from existing class called base class or parent class. The class which inherits from a base class is called derived classes or child class. For more clarity on this topic, let us have a look at 2 classes shown below. Here Class Car is Base Class and Class Ford is derived class.
class Car
public Car()
Console.WriteLine(“Base Class Car”);
public void DriveType()
Console.WriteLine(“Right Hand Drive”);
class Ford : Car
public Ford()
Console.WriteLine(“Derived Class Ford”);
public void Price()
Console.WriteLine(“Ford Price : 100K $”);
When we execute the following lines of code ,
Ford CarFord = new Ford();
Output Generated is as given below.
Base Class Car
Derived Class Ford
Right Hand Drive
Ford Price : 100K $
What this means is that, all the methods and attributes of Base Class car are available in Derived Class Ford. When an object of class Ford is created, constructors of the Base and Derived class get invoked. Even though there is no method called DriveType() in Class Ford, we are able to invoke the method because of inheriting Base Class methods to the derived class.

35. What is the reason behind the invention of C#?
Answer: C# is designed for Common Language Infrastructure (CLI). It contains the executable code and runtime environment that makes the users able to use various high-level languages on different computer platforms and architectures.

36. Now question is what are accessors?
Answer: The get and set portions or blocks of a property are called accessors. These are useful to restrict the accessibility of a property, the set accessor specifies that we can assign a value to a private field in a property and without the set accessor property it is like a read-only field. By the get accessor we can access the value of the private field, in other words it returns a single value. A Get accessor specifies that we can access the value of a field publically.
We have the three types of properties
For more details follow the link:
Property in C#
Properties in C#

37. What is extension method in c# and how to use them?
Answer: Extension methods enable you to add methods to existing types without creating a new derived type, recompiling, or otherwise modifying the original type. An extension method is a special kind of static method, but they are called as if they were instance methods on the extended type.

38. What is the difference between dispose and finalize methods in c#?
Answer: inalizer and dispose of both are used for same task as to free unmanaged resources but have some differences see.
Finalize used to free unmanaged resources those are not in use like files, database connections in application domain and more, held by an object before that object is destroyed.
In the Internal process it is called by Garbage Collector and can’t called manual by user code or any service.
Finalize belongs to System.Object class.
Implement it when you have unmanaged resources in your code, and make sure that these resources are freed when the Garbage collection happens.
Dispose is also used to free unmanaged resources those are not in use like files, database connections in Application domain at any time.
Dispose explicitly it is called by manual user code.
If we need to dispose method so must implement that class by IDisposable interface.
It belongs to IDisposable interface.
Implement this when you are writing a custom class that will be used by other users.

39. What is the GAC, and where is it located?
Answer: The GAC is the Global Assembly Cache. Shared assemblies reside in the GAC; this allows applications to share assemblies instead of having the assembly distributed with each application. Versioning allows multiple assembly versions to exist in the GAC—applications can specify version numbers in the config file. The gacutil command line tool is used to manage the GAC.

40. What is DLL Hell, and how does .NET solve it?
Answer: DLL Hell describes the difficulty in managing DLLs on a system; this includes multiple copies of a DLL, different versions, and so forth. When a DLL (or assembly) is loaded in .NET, it is loaded by name, version, and certificate. The assembly contains all of this information via its metadata. The GAC provides the solution, as you can have multiple versions of a DLL side-by-side. (C# .Net Training Videos)

41. What is the difference between “constant” and “readonly” variables in C#?
Answer: “Const” keyword is used for making an entity constant. We cannot modify the value later in the code. Value assigning is mandatory to constant variables.
“readonly” variable value can be changed during runtime and value to readonly variables can be assigned in the constructor or at the time of declaration.

42. What is Dynamic Dispatch?
Answer: Dynamic Dispatch becomes possible when each object carries data about its generating type, which is basically the object’s duty.

It is possible to achieve this when the type is able to keep track by using a virtual functions table, becoming the type’s duty. This allows an object to override some functions which have been inherited from its base type.

The bottom line is that when we place a call to a function, we don’t really know in an OO paradigm which function is really going to be executed.

In fact, it is the runtime’s duty to jump in when a call is placed on an object and determine which concrete function address to invoke, by looking at its generating type.

This constitutes the base of Polymorphism. If this sounds a bit intimidating, it will become clearer with an example going forward.

OO as a Mindset
One key aspect to understand is that it is possible to write OO code in a structured language like C, although the language itself was not designed with that paradigm in mind.

So it is not really the programming language that is object-oriented, but it’s more how we interact with it—how we use it.

It is true though those languages that are built from the ground up with OO fundamental core concepts and principles such as C#, make it easier for developers to implement code that is OO compliant, however, it is still largely known that many developers still use the language like they would use a procedural and structured language.

At the end of the day, OO is a shift in the thinking process on how developers write software. Some programming languages are better suited for this paradigm than others and C# is one of them.

43. Why do we still see so much non-OO code written in C# today?
The problem basically resides in the fact that it takes a deep understanding of OO in order to actually start writing code that behaves that way.

In order to really start thinking about how to properly implement OO code, it is critically important to know what data goes together with which operations—this consists of defining objects, their data, and operations.

Also, it is important to recognize which operations requests are dispatched dynamically—this consists of applying virtual functions and method overrides by means of inheritance, which leads to Polymorphism.

At this point, everything else pretty much comes as a byproduct of the other two core concept just mentioned: defining data and operations together and recognizing which operations are dynamically dispatched.

These lead to objects being brought to life. This allows operations to be determined dynamically and behavior modified by substituting objects.

So in short, the this pointer which is part of every instance and dynamic dispatching, which makes it possible to substitute one function specification with another during runtime—without affecting the caller, are at the core of OO.

The rest of the known OO principles such as Inheritance and Abstract Types are simply syntactical sugar on top of these two fundamental concepts.

44. What is Multithreading with .NET?
Answer: The real usage of a thread is not about a single sequential thread, but rather using multiple threads in a single program. Multiple threads running at the same time and performing various tasks is referred as Multithreading. A thread is considered to be a lightweight process because it runs within the context of a program and takes advantage of resources allocated for that program.

A single-threaded process contains only one thread while a multithreaded process contains more than one thread for execution.

System.Threading Namespace

Like many other features, in .NET, System.Threading is the namespace that provides various types to help in construction of multithreaded applications.

45. What is the difference between “dispose” and “finalize” variables in C#?
Answer: Dispose – This method uses interface – “IDisposable” interface and it will free up both managed and unmanaged codes like – database connection, files etc.
Finalize – This method is called internally unlike Dispose method which is called explicitly. It is called by garbage collector and can’t be called from the code.

46. How to move to a State-related Codebase?
Answer: So now that we’ve explored these concepts, let’s move to a state-related code base. So you might be asking yourself at this moment.

47. What are C# I/O Classes? What are the commonly used I/O Classes?
Answer: C# has System.IO namespace, consisting of classes that are used to perform various operations on files like creating, deleting, opening, closing etc.

Some commonly used I/O classes are:

File – Helps in manipulating a file.
StreamWriter – Used for writing characters to a stream.
StreamReader – Used for reading characters to a stream.
StringWriter – Used for reading a string buffer.
StringReader – Used for writing a string buffer.
Path – Used for performing operations related to the path information.

48. Define Property in C#.net?
Answer: Properties are members that provide a flexible mechanism to read, write or compute the values of private fields, in other words by the property we can access private fields. In other words we can say that a property is a return type function/method with one parameter or without a parameter. These are always public data members. It uses methods to access and assign values to private fields called accessors.

Note: Browse latest Dot Net Interview Questions and C# Tutorial Videos. Here you can check .net Training details and C# Training Videos for self learning. Contact +91 988 502 2027 for more information.

Leave a Comment