C#List <T>隐藏属性?

Jon*_*art 1 c# member-hiding

可能重复:
当IsReadOnly是接口成员时,List <T>如何使IsReadOnly成为私有的?

好的,这让我疯了.List<T>实施IList<T>.然而,

IList<int> list = new List<int>();
bool b = list.IsReadOnly;
bool c = ((List<int>)list).IsReadOnly;    // Error
Run Code Online (Sandbox Code Playgroud)

错误是:

'System.Collections.Generic.List'不包含'IsReadOnly'的定义,也没有扩展方法'IsReadOnly'接受类型为'System.Collections.Generic.List'的第一个参数'(你是否缺少using指令)或汇编参考?)

怎么会这样?这是否违反了我们告诉所有人的规则,关于不隐藏会员?这里的实施细节是什么?

Dig*_*der 5

因为实现是通过显式接口实现.

意思是它被定义为

bool IList<T>.IsReadOnly { get; set; //etc }
Run Code Online (Sandbox Code Playgroud)

http://msdn.microsoft.com/en-us/library/aa288461(VS.71).aspx

这就是为什么它不在List之外.