Implicit versus Explicit implementation of Interfaces in C#

What is the differences in implementing an interfaces implicitly or explicitly in C#?

Suppose we have an interface IWriter as follows

    public interface IWriter
    {
        public void WrtiteTo()
        { }
    }

Implicit: When we implement an interface implicitly, the implementing class exposes new behaviours. It is simply adding the methods, properties or other items required by the interface directly to the class and as public methods. So winding up, A member does this work for you in class which is implementing certain interface. Here is the sample which implements IWriter Interface implicitly:

    public class DocumentWriter : IWriter
    {
        #region IWriter Members
        public void WrtiteTo()
        {
            // Some Logic here
        }
        #endregion
    }

Implicit: On the other hand Explicit implementation are exposed by the use of interface itself itself. Here is the sample which implements IWriter Interface Explicitly:

    public class DocumentWriter : IWriter
    {
        #region IWriter Members
        void IWriter.WrtiteTo()
        {
             // Some Logic here
        }
        #endregion
    }
Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s