Explicit Interface Implementation

Self-Innovator
Posted by in OOPS category on for Intermediate level | Points: 250 | Views : 1144 red flag
Rating: 3 out of 5  
 1 vote(s)

This article gives a basic idea on achieving an Explicit Interface implementation.

Introduction

This article gives a basic idea on how to achieve Explicit Interface implementation.

Background

The explicit interface implementation in OOPS states how to use same method name in multiple interfaces, how the implementation part of same method name should be carried out.

Using the code

In this article we used two interfaces iTeacher,iStudent which will have a Name method.

    interface iTeacher
    {
        void Name();
    }
    interface iStudent
    {
        void Name();
    }
 class Program :iTeacher,iStudent
{ void iTeacher.Name() { Console.WriteLine("iteacher Interface Name Method"); } void iStudent.Name() { Console.WriteLine("iStudent Interface Name Method"); } static void Main(string[] args) { iStudent iS=new Program(); iS.Name(); iTeacher iT = new Program(); iT.Name(); Console.ReadKey(); } }
Output

In the above code, two interfaces used a common method as Name. The basic part of an interface is it must be implemented by a derived class in order to make use of an interface methods.

When the interfaces has got two methods with the same name then we need to use an Explicit Interface mechanism in order to achieve two identical implementations which can be achieved by using the interface name following a method name as per the syntax.


Conclusion

This article particularly focuses on how to make use of an explicit interfaces with the same method names.

Reference


http://blogs.msdn.com/b/mhop/archive/2006/12/12/implicit-and-explicit-interface-implementations.aspx

Page copy protected against web site content infringement by Copyscape

About the Author

Self-Innovator
Full Name: Sayeed Ahmed
Member Level: Bronze
Member Status: Member
Member Since: 12/22/2011 7:45:35 AM
Country: India
Join Hands Change lives Thanks & Regards Straight Edge Society


Login to vote for this post.

Comments or Responses

Login to post response

Comment using Facebook(Author doesn't get notification)