Why does IEnumerable.ToList() return List instead of IList?

前端 未结 10 1715
暖寄归人
暖寄归人 2020-12-29 02:23

The extension method ToList() returns a List. Following the same pattern, ToDictionary() returns a Dictionary<

10条回答
  •  独厮守ぢ
    2020-12-29 02:50

    In general when you call ToList() on a method you're looking for a concrete type otherwise the item could stay as type IEnumerable. You don't need to convert to a List unless you're doing something that requires a concrete list.

提交回复
热议问题