What's the difference between implementing an Interface explicitly or implicitly?

Posted by Rachel on Programmers See other posts from Programmers or by Rachel
Published on 2012-02-22T14:29:48Z Indexed on 2012/11/01 5:16 UTC
Read the original article Hit count: 401

Filed under:
|

In Visual Studio I can right-click on an interface and choose to Implement Interface, or Implement Interface Explicitly.

Visual Studio Screenshot

public class Test : ITest
{
    public string Id // Generated by Implement Interface
    {
        get { throw new NotImplementedException(); }
    }

    string ITest.Id // Generated by Implement Interface Explicitly
    {
        get { throw new NotImplementedException(); }
    }
}

The only difference I see between the two is that the Interface name is added to the interface properties and methods when they're created if you choose to Implement Interface Explicitly.

I find it makes the code a bit more readable since I can see where that method/property comes from, however does this make any difference in how the class is used or compiled? And does it really matter if I implement my interfaces implicitly or explicitly?

© Programmers or respective owner

Related posts about c#

Related posts about syntax