C# Tutorials and offshore development in India
    Tutorials   Resources   Forum   Reviews   Communities   Interview   Jobs   Projects   Training   Your Ad Here    
Silverlight Games | Mentor | Code Converter | Articles | Code Factory | Computer Jokes | Members | Peer Appraisal | IT Companies | Bookmarks | Polls | Revenue Sharing | Lobby | Gift Shop |


Prizes & Awards
My Profile



Active Members
TodayLast 7 Days more...






Resources » Code Snippets » C# Syntax »

Explicit Member Implementation in C#


Posted Date: 23 Mar 2007    Resource Type: Code Snippets    Category: C# Syntax
Author: janakiMember Level: Gold    
Rating: 1 out of 5Points: 10



If a class implements two interfaces which contain a method with the same signature and the class itself is having a method with the same signature, then implementing that method to the class leads to error. Explicit implementation is used to resolve this case. It’s nothing but calling the interface method name in a fully qualified manner. Call the method along with the interface name.


using System;
interface IMyinterface1
{
void display();
}

interface IMyinterface2
{
void display();
}

class trial:IMyinterface1,IMyinterface2 //interface implemented
{
public void display() //Method belongs to class trial
{
Console.WriteLine("Method from class trial");
}

void IMyinterface1.display() //explicit member implementation
{
Console.WriteLine("Method from Interface - IMyinterface1");
}

void IMyinterface2.display() //explicit member implementation
{
Console.WriteLine("Method from Interface - IMyinterface2");
}
}

class sample
{
public static void Main()
{
IMyinterface1 i1 = new trial(); //creating reference to interface
i1.display(); //calling interface method

IMyinterface2 i2 = new trial(); //creating reference to interface
i2.display(); //calling interface method

trial t = new trial();
t.display();
}
}



Responses


No responses found. Be the first to respond and make money from revenue sharing program.

Feedbacks      
Popular Tags   What are tags ?   Search Tags  
Sign In to add tags.
(No tags found.)

Post Feedback


This is a strictly moderated forum. Only approved messages will appear in the site. Please use 'Spell Check' in Google toolbar before you submit.
You must Sign In to post a response.
Next Resource: Simulation of a Clock using Enumerator with yield statements
Previous Resource: How to use the "Using" Statement
Return to Discussion Resource Index
Post New Resource
Category: C# Syntax


Post resources and earn money!
 
More Resources



dotNet Slackers

About Us    Contact Us    Privacy Policy    Terms Of Use