I finally got my blog back running, with an updated blog engine and a brand new theme. I think this may be an inspiration and look forward to trying to maintain a flow in my blog posts. Also, since most of my older posts were a bit dated anyway, I opted to not merge them into the new blog.
One of my current assignments consists of bringing new .net developers into our business, taking on the teacher role for a 2 year course in .net systems engineering. As part of this, I thought I’d document some of the nuggets found along the way.
It has been striking how few there actually are that know the difference between implementing an interface implicitly and implementing it explicitly, so that will be the initial post in this series.

Before we discuss the differences, let’s have a look at the basic interface to implement.
interface ICar
{
void Start();
void Stop();
void Drive();
}
This simple interface will be implemented on three different cars. First out is the StreetCar, implementing the interface the traditional way, implicitly. Apart from the methods from the interface, there is an additional method, Park(), not implemented from the interface.
class StreetCar : ICar
{
public void Start() {}
public void Stop() {}
public void Drive() {}
public void Park() {}
}
In order to compare, we’ll also add a RaceCar, with explicitly implemented interface.
class RaceCar : ICar
{
public void ICar.Start() {}
public void ICar.Stop() {}
public void ICar.Drive() {}
public void Race() {}
}
As you can see in the above sample, the methods are prefixed with the interface name. As in the previous snippet, there is a method not implemented from the interface.
Finally, let’s have fun and add a HybridCar, and you guessed it – this time we’ll implement the interface both implicitly and explicitly.
class HybridCar : ICar
{
public void Start() {}
public void Stop() {}
public void Drive() {}
public void ICar.Start() {}
public void ICar.Stop() {}
public void ICar.Drive() {}
public void Reverse() {}
}
To test things out, we will use a CarShop, configured as below.
class CarShop
{
CarShop()
{
StreetCar skoda1 = new StreetCar();
ICar skoda2 = new StreetCar();
RaceCar ferrari1 = new RaceCar();
ICar ferrari2 = new RaceCar();
HybridCar bmw1 = new HybridCar();
ICar bmw2 = new HybridCar();
}
}
Using this CarShop, we will be able to use intellisense to see some interesting behavior.

Whereas the StreetCar and HybridCar may seem similar in result, the RaceCar differs in an apparent way. When declared as a RaceCar, the instance will not show any of the methods explicitly implemented from the interface. Only the Race() method shows up.
As for the instances declared by interface ([CarType2]), they all look the same, but the RaceCar and HybridCar has the most in common. In those cases, the methods prefixed with ICar. (explicitly implemented) will be called. The StreetCar will apply the implicitly implemented method.
When declared by type, the SteetCar and HybridCar have common implementations, where the implicit implementations will be called.
To sum things up, the HybridCar will allow for different implementations and different behavior depending on whether it is declared “by type” or “by interface”. By type results in the implicit implementations being called while “by interface” results in the explicit implementations being called. The RaceCar only allows for the interface methods being called when declared “by interface” while the StreetCar will not make a difference between declaration method.