C#和.Net为什么所有数组都继承自IList? [英] C# and .Net why do all arrays inherit from IList?
本文介绍了C#和.Net为什么所有数组都继承自IList?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我最近注意到C#中的所有数组都是从IList接口继承的,但是您不能真正像标准列表那样处理数组.
I recently noticed that all arrays in C# inherit from the IList interface but you can't really handle an array like a standard list.
为什么在.net和C#中引入这种继承
Why was this inheritance introduced in .net and C#
推荐答案
能够将 any IList
传递给某种算法通常很有用.该算法可能只是关心能够索引到该集合中.许多东西都可以满足此要求:数组,List<T>
,许多自定义集合.
It is often useful to be able to pass any IList
to some algorithm. That algorithm might just care about being able to index into this collection. Many things fulfill this requirement: Arrays, List<T>
, many custom collections.
这篇关于C#和.Net为什么所有数组都继承自IList?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文