如何名单< T>使当IsReadOnly是一个接口成员IsReadOnly私人? [英] How does List<T> make IsReadOnly private when IsReadOnly is an interface member?
问题描述
我创建一个专门的代理类,它实现的IList< T>
和包装内部列表< T>
本身实现的IList< T> $>实例
I'm creating a specialised proxy class that implements IList<T>
and wraps an internal List<T>
instance.
C $ C>,它声明了一个成员的 BOOL IsReadOnly ,但是当我试图从我自己的类访问员,我不能因为在
列表< T> 。code>,IsReadOnly是私人
List<T>
itself implements IList<T>
, which declares a member bool IsReadOnly, but when I try to access that member from my own class, I can't because in List<T>
, IsReadOnly is private.
所以我的问题是;如果一个接口的实现需要所有实现成员是公开的,为什么列表< T>
得到IsReadOnly实现私有,因此拒绝我访问它。
So my question is; if an implementation of an interface requires all implemented members to be public, why does List<T>
get to implement IsReadOnly as private and thus deny me access to it?
推荐答案
它实现了接口成员明确。
It implements the interface member explicitly.
的 http://msdn.microsoft.com/en-us/library/aa288461(VS.71)的.aspx
请注意,这并不能使接口成员私人
。它仍然可以公开,但只有当你看对象通过接口(含铸造)。
Note that this does not make the interface member private
. It's still available publicly, but only if you look at the object through the interface (with casting).
这篇关于如何名单< T>使当IsReadOnly是一个接口成员IsReadOnly私人?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!