这个问题已经在这里有了答案:




已关闭10年。






真的很奇怪:

C#数组,如下所示

double[] test = new double[1];

支持Length属性以获取数组的大小。但是数组也实现了一个IList接口(interface):
IList<double> list = test;

但是,IList接口(interface)还提供了Count属性。数组(在这种情况下为“test”)为什么没有?

编辑:感谢所有人指出,实际上是提供Count属性的ICollection接口(interface)(不是IList),并且这是由于该接口(interface)的显式实现所致。

最佳答案

简而言之,他们选择将其称为Length,并通过显式接口(interface)实现来实现Count,例如:

int ICollection.Count { get { return Length; } }

关于c# - 为什么C#数组没有Count属性?,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/4769971/

10-12 00:24
查看更多