Introduction
An interface in C# is usually used to create loosely coupled and contract-based designs. It can contain signatures (declarations) of the Methods, Properties, Indexers, and Events. The implementation of the methods/properties and so on is done in the class that implements the interface. An interface can inherit one or more interfaces; in other words, it supports multiple inheritance, whereas classes don't.
Implicit interface implementation
This is the most regular or obvious way to implement members of an interface. Here we don't specify the interface name of the members and implement implicitly. The method can be declared at any interface (s) the class implements.
Example
interface ITest
{
void TestMethod();
}
class TestClass : ITest
{
public void TestMethod()
{
Console.WriteLine("Implicit Interface Implementation");
}
}The call of the method is also not different. Just create an object of the class and invoke it.
class Program
{
static void Main(string[] args)
{
TestClass obj = new TestClass();
obj.TestMethod(); // Way to call implicitly implemented method
}
}Output
Explicit interface implementation
This is another way to implement members of an interface. Here we need to specify the; interface name of the members. The following example explains that.
class TestClass : ITest
{
void ITest.TestMethod()
{
Console.WriteLine("Explicit Interface Implementation");
}
}The constraint with explicit implementation is that an explicitly implemented member cannot be accessed using a class instance, but only through an instance of the interface. Please have a look at the example below.
class Program
{
static void Main(string[] args)
{
ITest obj2 = new TestClass();
obj2.TestMethod();
}
}Output
I hope you have liked the article. Please share your comments.


Prakash TripathiTOP 100Posted May 5, 2016, 2:03 AM EDT
Thnx Nitin.
Prakash TripathiTOP 100Posted May 5, 2016, 2:03 AM EDT
Thnx Karthik.
Prakash TripathiTOP 100Posted May 5, 2016, 2:03 AM EDT
Thnx Vipul.
Prakash TripathiTOP 100Posted May 5, 2016, 2:03 AM EDT
Thnx Bhuvanesh.
Bhuvanesh MohankumarPosted May 5, 2016, 1:53 AM EDT
Yes it was helpful
Vipul MalhotraPosted Jun 30, 2015, 7:25 AM EDT
Good article
Karthik Muthu KaruppanPosted Apr 24, 2015, 7:03 AM EDT
Good one
NitinPosted Apr 24, 2015, 5:59 AM EDT
Good one
Gennady PodpletennyPosted Apr 24, 2015, 5:12 AM EDT
((ITest)obj2).TestMethod();
Prakash TripathiTOP 100Posted Apr 23, 2015, 9:26 PM EDT
Hi Prashant. One of the real word scenario could be that you have two interfaces, both with the same method and different implementations, then you have to implement explicitly. another could be that you have an internal interface and you don't want to implement the members on your class publicly, you would implement them explicitly. Implicit implementations are required to be public
Gowtham RajamanickamTOP 100Posted Apr 23, 2015, 8:41 PM EDT
nice
Prashant SharmaPosted Apr 23, 2015, 11:08 AM EDT
Nicely explain!!! Can you also explain, what are the real time scenario where we should use explicit interface implementation?