开发者

Method hiding in C# classes

开发者 https://www.devze.com 2023-03-13 01:34 出处:网络
I\'m looking at LinkedList class implementation in C# and I cannot understand how Add method is hidden.

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

精彩评论

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