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

前端 未结 10 1733
暖寄归人
暖寄归人 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:31

    I believe that the decision to return a List<> instead of an IList<> is that one of the more common use cases for calling ToList is to force immediate evaluation of the entire list. By returning a List<> this is guaranteed. With an IList<> the implementation can still be lazy, which would defeat the "primary" purpose of the call.

提交回复
热议问题