Ehsan Ghanbari

Experience, DotNet, Solutions

Explicit interface in C#

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!

About Me

Ehsan Ghanbari

Hi! my name is Ehsan. I'm a developer, passionate technologist, and fan of clean code. I'm interested in enterprise and large-scale applications architecture and design patterns and I'm spending a lot of my time on architecture subject. Since 2008, I've been as a developer for companies and organizations and I've been focusing on Microsoft ecosystem all the time. During the&nb Read More

Post Tags
Pending Blog Posts
Strategic design
Factory Pattern
time out pattern in ajax
Selectors in Jquery
Peridic pattern
How to use PagedList In asp.net MVC
Redis as a cache server
Domain driven design VS model driven architecture
How to query over Icollection<> of a type with linq
What's the DDD-lite?
comments powered by Disqus