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