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
精彩评论