Freely convert between List and IEnumerable

前端 未结 6 960
逝去的感伤
逝去的感伤 2020-12-04 08:21

How can I convert a List to an IEnumerable and then back again?

I want to do this in order to run a series

6条回答
  •  不思量自难忘°
    2020-12-04 08:44

    A List is an IEnumerable, so actually, there's no need to 'convert' a List to an IEnumerable. Since a List is an IEnumerable, you can simply assign a List to a variable of type IEnumerable.

    The other way around, not every IEnumerable is a List offcourse, so then you'll have to call the ToList() member method of the IEnumerable.

提交回复
热议问题