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():

 

  1.  public interface IBankingA
  2.     {
  3.         void WithDraw();
  4.     }
  5.  
  6.     public interface IBankingB
  7.     {
  8.         void WithDraw();
  9.     }

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 same name by typing the interface name before the method name like this:

  1.  public class Baking :IBankingA, IBankingB
  2.     {
  3.         void IBankingA.WithDraw()
  4.         {
  5.             throw new NotImplementedException();
  6.         }
  7.  
  8.         void IBankingB.WithDraw()
  9.         {
  10.             throw new NotImplementedException();
  11.         }
  12.     }

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. I spend a lot of time on software architecture. Since 2008, I've been as a developer for different companies and organizations and I've been focusing on Microsoft ecosystem all the time. During the past years, Read More

Post Tags
Pending Blog Posts
using Elmah in asp.net MVC4
Using FluentSecurity in MVC
Strategic design
Factory Pattern
time out pattern in ajax
Redis as a cache server
How to use PagedList In asp.net MVC
Multiple submit buttons in asp.net MVC
Domain driven design VS model driven architecture
What's the DDD-lite?
comments powered by Disqus