Pergunta de entrevista da empresa ETX Capital

Why do people call ToArray() amd ToList() on IEnumerbable?

Resposta da entrevista

Sigiloso

20 de ago. de 2022

I explained how IEnumerable is an interface that can be applied to a collection, with a built in pointer, iterator, and distributer. You typically use it to step through an indeterminately-sized collection using the Yield Return keywords, looking for some item of interest. So you don't need to retrieve a massive data set to find one item. You can call ToList() or ToArray() on such a collection to turn it into an in-memory collection instead. Which probably would indicate you didn't need an IEnumerable in the first place.