Article Overview
- Background
- Prerequisites
- Why is Explicit Interface Implementation required?
- How to do Explicit Interface Implementation?
- How to do Default & Explicit Implementation?
- Summary
Background
A class inherits from 2 interfaces and both the interfaces have the same method name. Using explicit interface implementation the class should implement the method for both the interfaces.
There are various situations where you need to provide the same method name to multiple interfaces. Therefore at the time of implementation/inheritance you need to specify explicitly interface implementation with method names. This is known as Explicit Interface Implementation.
Let us go with some practical examples to know more about the Explicit Interface Implementation as follows:
- Why is Explicit Interface Implementation required?
- How to do Explicit Interface Implementation?
- How to do Default & Explicit Implementation?
Prerequisites
You should have a basic knowledge of Interface Implementation in C#.
Why is Explicit Interface Implementation required?
To solve the following kind of problem Explicit Interface Implementation technique is used.
- using System;
- namespace ConsoleApplication1
- {
- interface ICircle
- {
- void Area();
- }
- interface IRectangle
- {
- void Area();
- }
- public class Shape : ICircle, IRectangle
- {
- public void Area()
- {
- Console.WriteLine("Circle/Rectangle Area");
- }
- }
- class Program
- {
- static void Main(stri[] args)
- {
- Shape shape = new Shape();
- ((ICircle)shape).Area();
- ((IRectangle)shape).Area();
- Console.ReadLine();
- }
- }
- }
Output
Circle/Rectangle Area
Circle/Rectangle Area
Here, you can see that both times the same method is called.
Therefore, to implement both methods separately for interface Circle and Rectangle you have to do it with Explicit Interface Implementation as follows.

Join the conversation! Your thoughts help the community grow.