请参阅System.Array类的定义
public abstract class Array : IList, ...
Run Code Online (Sandbox Code Playgroud)
从理论上讲,我应该能够写下这一点,并感到高兴
int[] list = new int[] {};
IList iList = (IList)list;
Run Code Online (Sandbox Code Playgroud)
我也应该可以从iList中调用任何方法
ilist.Add(1); //exception here
Run Code Online (Sandbox Code Playgroud)
我的问题不是为什么我得到一个例外,而是为什么Array实现了IList?
您可能知道,C#中的数组实现IList<T>了其他接口.但不知何故,他们这样做没有公开实现Count属性IList<T>!数组只有一个Length属性.
这是一个明显的例子,C#/ .NET打破了自己关于接口实现的规则,还是我错过了什么?