且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

为什么IEnumerable< T> .ToList< T>()返回List< T>而不是IList< T>?

更新时间:2022-04-02 21:01:39

返回列表< T> List< T> 的那些方法不属于 IList< T> 的优点很容易使用。您可以使用 List< T> 执行很多操作,而 IList< T> 则无法执行此操作>。

Returning List<T> has the advantage that those methods of List<T> that are not part of IList<T> are easily used. There are a lot of things you can do with a List<T> that you cannot do with a IList<T>.

相比之下,查询< TKey,TElement> 只有一个可用的方法 ILookup< TKey,TElement> 没有( ApplyResultSelector ),你可能不会最终使用它。

In contrast, Lookup<TKey, TElement> has only one available method that ILookup<TKey, TElement> does not have (ApplyResultSelector), and you probably would not end up using that anyway.