Implicit Implementation
Let's take an example to understand, what implicit and explicit implementation of interface is.
I am going to create an interface named with “IEmployee” and a class named with “Employee”.
When the class implements the interface member, it does not need to specify the interface name with the member name. We can simply implement it.
- interface IEmployee
- {
- void Greeting();
- }
- public class Employee : IEmployee
- {
- public void Greeting()
- {
- Console.WriteLine("This is implicitly implementation of Interface");
- }
- }
When we need to access this method, we can create the instance of the class and when we pass object, then it gives the name of implemented method. See the following code.
- class Program
- {
- static void Main(string[] args)
- {
- Employee emp = new Employee();
- emp.Greeting();
- Console.ReadLine();
- }
- }
Sometimes, we get a situation where a class implemented the multiple interface and those interfaces contain the same name method. When class is going to implement the interface members, they don’t differentiate between the method, because of the method name or same in both the interfaces.
For resolving this issue we need to specify the name of the interface at the time of implementation explicitly.
Let's take an example to understand what explicit implementation of interface is. I am going to create one more interface “IManager” which will be implemented by Employee class. IManager contains the same name method as IEmployee contains. So, the question is that how we will implement the IManager member method. Have a look in the following example.
- using System;
- namespace ConsoleDemo
- {
- interface IEmployee
- {
- void Greeting();
- }
- interface IManager
- {
- void Greeting();
- }
- public class Employee : IEmployee, IManager
- {
- void IEmployee.Greeting()
- {
- Console.WriteLine("This is greeting for Employee");
- }
- void IManager.Greeting()
- {
- Console.WriteLine("This is greeting for Manager");
- }
- }
- class Program
- {
- static void Main(string[] args)
- {
- IEmployee emp = new Employee();
- emp.Greeting();
- IManager man = new Employee();
- man.Greeting();
- Console.ReadLine();
- }
- }
- }
- Access modifier has been removed from the Greeting() method.
- The Greeting() method name showed only with the interface name [explicitly].
One more thing, you have noticed here that when we need to access the implemented method using instance of class, we use the interface name for creating the instance of the class.
- IEmployee emp = new Employee();
- emp.Greeting();
- IManager man = new Employee();
- man.Greeting();
Thanks for reading and I hope you enjoyed this article.

Mukesh KumarPosted Oct 18, 2015, 4:56 AM
Thanks Santhakumar
Santhakumar MunuswamyPosted Oct 18, 2015, 4:47 AM
Good one
Mukesh KumarPosted Oct 16, 2015, 8:14 AM
Thanks Yudi
Yaduveer SainiPosted Oct 16, 2015, 5:37 AM
Good Job Sir...keep it up
Banketeshvar NarayanPosted Oct 16, 2015, 3:33 AM
Great job.. Keep it up!
Mukesh KumarPosted Oct 9, 2015, 1:51 AM
Thanks sir
Sibeesh VenuPosted Oct 9, 2015, 1:12 AM
Nice Share
Mukesh KumarPosted Oct 8, 2015, 9:27 AM
Thanks
Nilesh JadavPosted Oct 8, 2015, 9:08 AM
Nice one sir
Mukesh KumarPosted Oct 8, 2015, 8:37 AM
Thanks Vipul
Vipul MalhotraPosted Oct 8, 2015, 7:46 AM
nice explanation