Different between explicit interface and implicit interface in c#. [Resolved]

Posted by Programmer123 under C# on 11/23/2013 | Points: 10 | Views : 5287 | Status : [Member] | Replies : 4
Can any one tell me what is different between explicit interface and implicit interface in c#. In which case to use both? Please give some examples.




Responses

Posted by: Allemahesh on: 11/25/2013 [Member] [MVP] Silver | Points: 50

Up
0
Down

Resolved
Implicit is when you define your interface via a member on your class. Explicit is when you define methods within your class on the interface. I know that sounds confusing but here is what I mean: IList.CopyTo would be implicitly implememnted as:

public void CopyTo(Array array, int index)
{
throw new NotImplementedException();
}


and explicity as:

void ICollection.CopyTo(Array array, int index)
{
throw new NotImplementedException();
}


The difference being that implicitly is accessible throuh your class you created when it is cast as that class as well as when its cast as the interface. Explicit implentation allows it to only be accessible when cast as the interface itself.

myclass.CopyTo //invalid with explicit
((IList)myClass).CopyTo //valid with explicit.


Happy Coding,
If it helps you or directs U towards the solution, MARK IT AS ANSWER



Programmer123, if this helps please login to Mark As Answer. | Alert Moderator

Posted by: Vamc on: 12/17/2013 [Member] Starter | Points: 25

Up
0
Down
Click on the below link to know about interface

http://www.dotnetchallengers.com/App_Folder/Content/Tutorials/Interface/Interface.aspx

Programmer123, if this helps please login to Mark As Answer. | Alert Moderator

Posted by: Vamc on: 12/17/2013 [Member] Starter | Points: 25

Up
0
Down
Click below link to know about interface

http://www.dotnetchallengers.com/App_Folder/Content/Tutorials/Interface/Interface.aspx

Programmer123, if this helps please login to Mark As Answer. | Alert Moderator

Login to post response