Sibeesh Passion

C sharp Interview Questions And Answers


In this article we will discuss about the most asked C# interview questions and answers. If you need to know other interview questions and answers, I strongly recommend to follow this link: Interview Questions. Now in this post we are going to share the interview questions for C# or a Dot Net developer. No matter you are experienced or fresher, it is important that you must aware of these. 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#. You can always read my other interview questions here in the below links.

  • Interview Questions For Experienced and Beginner .NET Professionals
  • Infosys Interview Questions For DotNet Professionals
  • SQL Interview Questions And Answers
  • Important ADO.NET Interview Questions

    So shall we now discuss about C# interview questions?

    C# Interview Questions

    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 library 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, class members.
  • Only abstract classes can have abstract methods.
  • Syntax

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

    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.  

    What are Interface? Explain with an example?

    An interface is useful when you want to be able 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.
    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.   

    Explain The Difference Between Abstract Class and Interface ?

    An Abstract class doesn’t 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.

    Explain Generic Collections & Array Lists ?

    Generics 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, generics 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(); 



    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, &c. 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 anymore 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 done.

    – It will show effect on performance of website and it will not suitable to free objects immediately.

    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 in to database, this design will not suffice. I will have create another class that has a method that sends email and create its instance in the ApplicationWatcher.

    What is Data Encapsulation and explain its Implementation?

    To know about the Data encapsulation in C#, I recommend you to read here:
    Data Encapsulation and Its Implementation

    That’s all. Have a great day.


    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?

    A blog isn’t a blog without comments, but do try to stay on topic. If you have a question unrelated to this post, you’re better off posting it on C# Corner, Code Project, Stack Overflow, Asp.Net Forum instead of commenting here. Tweet or email me a link to your question there and I’ll definitely try to help if I can.

    Kindest Regards
    Sibeesh Venu

    • Ajay Bhasy

      If its a Windows Application oriented Interview, then its good to have a look at threading as well. Having a look at design patterns and IOC container in Dependency Injection is also good. Hope to see another article with these area covered.

    • Ram

      It’s very use full for beginners and experienced professionals .
      Thanks Sibeesh…..

      • Million thanks for your feedback. Much appreciated.

    Footer With Address And Phones