Explicilty Implement Interface Concept In C Sharp


We need to implement an interface explicilty in case when we have same member name within different interface.
-------------------------------------------------------------------------------------------------------
using System;
interface Rectangle
{
void Area();
}
interface Parallelogram
{
void Area();
}
class ExplicitlyInterfaceConcept : Rectangle, Parallelogram
{
int area;
void Rectangle.Area()       //We need to prefix interface name in case of explicit implementation.
{
int i_length =20, i_width= 10;
area = i_length * i_width;
Console.WriteLine("Area Of Rectangle is " + area);
}
void Parallelogram.Area()   //We need to prefix interface name in case of explicit implementation.
{
int i_base = 10, i_height=50;
area = i_base * i_height;
Console.WriteLine("Area Of Parallelogram is " + area);
}
static void Main()
{
ExplicitlyInterfaceConcept eic_obj = new ExplicitlyInterfaceConcept();

Rectangle rec_obj = (Rectangle)eic_obj;
rec_obj.Area();

Parallelogram par_obj = (Parallelogram)eic_obj;
par_obj.Area();
}
}
------------------------------------------------------------------------------------------------------


Explicilty Implement Interface Concept In C Sharp Explicilty Implement Interface Concept In C Sharp Reviewed by Baljeet Singh on 06:16 Rating: 5

No comments:

Powered by Blogger.