Explanation why IEnumerable is more efficient than a List

前端 未结 7 1810
北荒
北荒 2021-01-30 08:35

I keep hearing that in .net 3.5 you should use IEnumerable over a List, but I can’t find any reference materials or articles that explain why it’s so much more proficient. Does

7条回答
  •  感情败类
    2021-01-30 09:12

    IEnumerable is not more efficient than a List as a List is an IEnumerable.

    The IEnumerable interface is simply .NET's way of using the iterator pattern, nothing more.

    This interface can be implemented on many types (List included) to allow those types to to return iterators (i.e. instances of IEnumerator) so that the caller can iterate a sequence of items.

提交回复
热议问题