Implicit and explicit interface inheritance/implementation in C#

In the book "MCSD cert toolkit" in which I found a good question that asks the core difference between  implicit and explicit interface implementation .

Suppose the HouseBoat class implements the IHouse interface implicitly and the IBoat interface explicitly. Which of the following statements is false?
a .  The code can use a HouseBoat object to access its IHouse members.
b .  The code can use a HouseBoat object to access its IBoat members.
c .  The code can treat a HouseBoat object as an IHouse to access its IHouse members.
d .  The code can treat a HouseBoat object as an IBoat to access its IBoat members.

For this question, The HouseBoat Class will firstly-implicitly implement the IHouse interface. Then It inherits secondly-explicitly the IBoat interface.
-  The c and d options are obiviously correct.
- the a option is correct.
So the remained option is b is false. This could explain that the C# team is not to encourage using explicit implementation. To use a HouseBoat object accessing its IBoat member, we must cast the HouseBoat to IBoat. For example:
HouseBoat x=new HouseBoat();
IBoat x= (IBoat)x;

Share on Google Plus

About Chien

This is a short description in the author block about the author. You edit it by entering text in the "Biographical Info" field in the user admin panel.

0 comments:

Post a Comment