好的,这让我疯了.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指令)或汇编参考?)
怎么会这样?这是否违反了我们告诉所有人的规则,关于不隐藏会员?这里的实施细节是什么?
因为实现是通过显式接口实现.
意思是它被定义为
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之外.
| 归档时间: |
|
| 查看次数: |
332 次 |
| 最近记录: |