Blog

Filter posts by Category Or Tag of the Blog section!

Explicit interface in C#

Friday, 28 February 2014

You have used millions of times, but you maybe don’t know what they call it (I just saw it and I didn't know too). Suppose these two interfaces with a member Called WithDraw():

 

 public interface IBankingA
    {
        void WithDraw();
    }

    public interface IBankingB
    {
        void WithDraw();
    }

 

Now If you want to implement the members of these two interfaces in a class, you should tell the compiler that I'm implementing the members of both interfaces as they have the same name by typing the interface name before the method name like this:

 

public class Baking :IBankingA, IBankingB
    {
        void IBankingA.WithDraw()
        {
            throw new NotImplementedException();
        }

        void IBankingB.WithDraw()
        {
            throw new NotImplementedException();
        }
    }

That's it!

Category: Software

Tags: C#

comments powered by Disqus