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.
Background
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.
Properties
- 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.
Syntax
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.
Example
// 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.
Properties
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.
Example
interface IControl
{
void Paint();
}
interface ISurface
{
void Paint();
}
public class SampleClass: IControl, ISurface
{
void IControl.Paint()
{
System.Console.WriteLine("IControl.Paint");
}
void ISurface.Paint()
{
System.Console.WriteLine("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.

Vinay KPosted Mar 15, 2017, 7:38 AM
Clear Explanation ... thank you dear Sibeesh.
Sibeesh VenuPosted Oct 27, 2015, 12:51 AM
Nitin Pandit Thanks a lot dear :)
Sibeesh VenuPosted Oct 27, 2015, 12:51 AM
Debendra Dash Thanks a lot :)
Sibeesh VenuPosted Oct 27, 2015, 12:51 AM
Anoop Kumar Sharma Thanks a lot :)
Sibeesh VenuPosted Oct 27, 2015, 12:50 AM
Priyaranjan K S Thanks a lot :)
Sibeesh VenuPosted Oct 27, 2015, 12:50 AM
Mukesh Kumar Thanks a lot :)
Sibeesh VenuPosted Oct 27, 2015, 12:50 AM
Nilesh Jadav Thanks a lot :)
Sibeesh VenuPosted Oct 27, 2015, 12:50 AM
Upendra Pratap Shahi Thanks a lot :)
Nitin PanditPosted Oct 27, 2015, 12:30 AM
great n nice explanations dear :)
Debendra DashPosted Oct 26, 2015, 3:15 PM
thanks sibesh......
Anoop Kumar SharmaPosted Oct 26, 2015, 2:19 PM
Nice one. Thanks for sharing :-)
Priyaranjan K SPosted Oct 26, 2015, 8:25 AM
Good One .
Mukesh KumarPosted Oct 26, 2015, 8:17 AM
Good Job
Nilesh JadavPosted Oct 26, 2015, 6:47 AM
Nice Share sir !!
Upendra Pratap ShahiPosted Oct 26, 2015, 6:27 AM
Thanks for sharing sir....
Sibeesh VenuPosted Oct 26, 2015, 6:02 AM
Harshad Pansuriya Thank you
Harshad PansuriyaPosted Oct 26, 2015, 4:39 AM
nice one