C# Tutorials and offshore development in India
    Tutorials   Resources   Forum   Communities   Interview   Jobs   Projects   Offshore Development    
Silverlight Tutorials | Mentor | Code Converter | Articles | Code Factory | Computer Jokes | Members | Peer Appraisal | IT Companies | Bookmarks | Revenue Sharing |


Prizes & Awards
My Profile



Active Members
TodayLast 7 Days more...

New Feature: Community Sites: Create your own .NET community website and start earning from Google AdSense ! It's Free !




Explicit Member Implementation in C#


Posted Date: 23 Mar 2007    Resource Type: Code Snippets    Category: C# Syntax

Posted By: janaki       Member Level: Gold
Rating:     Points: 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  
(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!
 
Related Resources



dotNet Slackers   BizTalk Adaptors    Web Design

web conferencing

Contact Us    Privacy Policy    Terms Of Use