开发者

Method hiding in C# classes

I'm looking at LinkedList class implementation in C# and I cannot understand how Add method is hidden.

LinkedList implements ICollection which has an Add method. In the LinkedList class code the Add method is declared as:

void ICollection<T>.Add(T value);

How it is possible to have internal meth开发者_运维百科od which is declared in the interface?


The interface is implemented explicitly.

Explicilty implemented interface members can only be accessed through an instance of the implemented interface, like so:

LinkedList list;
((ICollection)list).Add(...)

Check this SO question and answer for more information: implicit vs explicit interface implementation

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜