Most Asked C# Interview Questions And Answers

If you need to know other interview questions and answers, I strongly recommend to read my following articles:

Important ADO.NET Interview Questions

SQL Interview Questions And Answers

Now in this post we are going to share the interview questions for C# or a Dot Net developer. No matter you are an experienced professional or a fresher, it is important that you must be aware of these questions. So please read it carefully. I hope you will like this article.


C# is one of my favorite programming language. So I am really happy to share you some interview questions related to C#. So shall we now discuss about C# interview questions?

Question: What are Abstract Classes?

The purpose of an abstract class is to define some common behavior that can be inherited by multiple subclasses, without implementing the entire class. In C#, the abstract keyword designates both an abstract class and a pure virtual method.

The purpose of an abstract class is to provide a common definition of a base class that multiple derived classes can share. For example, a class library may define an abstract class that is used as a parameter to many of its functions, and require programmers using that libarary to provide their own implementation of the class by creating a derived class.


  • An abstract class cannot be instantiated.
  • It can be inherited.
  • It can have method implementations and class members.
  • Only abstract classes can have abstract methods.


public abstract class A
   public abstract void DoWork(int i);

Question: What are Abstract methods? Give an example?

Abstract Methods

Abstract methods have no implementation, so the method definition is followed by a semicolon instead of a normal method block. (See above example for syntax).

Derived classes of the abstract class must implement all abstract methods.

When an abstract class inherits a virtual method from a base class, the abstract class can override the virtual method with an abstract method.


// compile with: /target:library   
public  class D  
    public  virtual  void DoWork(int i)   
        // Original implementation.  
public  abstract  class E: D  
    public  abstract  override  void DoWork(int i);  
public  class F: E  
    public  override  void DoWork(int i)   
       // New implementation.  

Question: What is Interface? Explain with an example?

An interface is useful when you want to use some common functionality of otherwise unrelated classes- they share no implementation details, only the function signatures. In C#, function declarations within an interface are implicitly pure virtual.

An interface contains only the signatures of methods, properties, events or indexers. A class or struct that implements the interface must implement the members of the interface that are specified in the interface definition. 


An interface can be a member of a namespace or a class and can contain signatures of methods, properties, events, indexers, etc.

An interface can inherit from one or more base interfaces.

A class that implements an interface can explicitly implement members of that interface. An explicitly implemented member cannot be accessed through a class instance, but only through an instance of the interface.


interface IControl   
    void Paint();   
interface ISurface   
    void Paint();   
public  class SampleClass: IControl, ISurface   
    void IControl.Paint()   
    void ISurface.Paint()   

Calling the methods

// Call the Paint methods from Main.  
SampleClass obj = new SampleClass();  
//obj.Paint(); // Compiler error.  
IControl c = (IControl)obj; c.Paint();  
// Calls IControl.Paint on SampleClass.  
ISurface s = (ISurface)obj; s.Paint();  
// Calls ISurface.Paint on SampleClass.   

Question: Explain The Difference Between Abstract Class and Interface?

An Abstract class do not provide full abstraction but an interface does provide full abstraction; i.e. both a declaration and a definition is given in an abstract class but not so in an interface.

Using Abstract we cannot achieve multiple inheritance but using an Interface we can achieve multiple inheritance.

We cannot declare a member field in an Interface.

We cannot use any access modifier i.e. public, private, protected, internal, etc. because within an interface by default everything is public.

An Interface member cannot be defined using the keyword static, virtual, abstract or sealed.

Question: Explain Generic Collections & Array Lists?

Generic allow you to delay the specification of the data type of programming elements in a class or a method, until it is actually used in the program. In other words, generic allow you to write a class or method that can work with any data type.

Generic Collections helps us to create flexible type-safe, strong type collections at compile time.


List<int> myInts = new List<int>();




They are ordered collection of objects, that can be resized automatically, that has dynamic memory allocation and which can contain different types of data.

Arraylist stores its members as objects, so in order to retrieve it we must type cast it.

Syntax and Example

ArrayList intlist = new ArrayList();  



Question: What are Finalize and Dispose? Can you list down the differences between them?

Finalizers are run by the Garbage Collection before an object that is eligible for collection is reclaimed. Dispose() is meant for cleaning up unmanaged resources, like network connections, files, handles to OS stuff, etc. It works best in conjunction with the using block where the compiler makes sure that Dispose() will be called immediately once you are done with an object – and also ensures that you cannot work with the object any more once it’s disposed.

Dispose() Method

  • This dispose method will be used to free unmanaged resources like files, database connection, etc.
  • To clear unmanaged resources we need to write code manually to raise dispose() method.
  • This Dispose() method belongs to IDisposable interface.
  • If we need to implement this method for any custom classes we need to inherit the class from IDisposable interface.
  • It will not show any effect on performance of website and we can use this method whenever we want to free objects immediately.

Finalize() Method

  • This method also free unmanaged resources like database connections, files, etc.
  • It is automatically raised by garbage collection mechanism whenever the object goes out of scope.
  • This method belongs to object class.
  • We need to implement this method whenever we have unmanaged resources in our code and make sure these resources will be freed when garbage collection process is done.
  • It will show effect on performance of website and it will not be suitable to free objects immediately.

Question: What is Dependency Injection? How can we implement it?

Simply put Dependency injection is for decoupling two components. It can be explained by a simple example.

public class ErrorLogger  
    public void WriteIntoDataBase(string message)  
        // Creates DataBase Entry.  
public class ApplicationWatcher  
    ErrorLogger logger = new ErrorLogger();  
    public void Notify()  
        logger.WriteIntoDataBase("This is the message that I want to write.")  

Have a look at the code above.

I have an ErrorLogger class that writes an error in to database. The method is actually called from another class ApplicationWatcher.

In a later stage if I want to send an email instead of writing it to database, this design will not suffice. I will have to create another class that has a method that sends email and create its instance in the ApplicationWatcher.


Did I miss anything that you may think which is needed? Could you find this post as useful? I hope you liked this article. Please share me your valuable suggestions and feedback.

Your turn. What do you think?

If there is any question, then please mention it in the comments section.

Read this article in my blog here.

You can enhance your knowledge more, by reading the following articles.