Sollicitatievraag bij ETX Capital

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

Antwoord op sollicitatievraag

Anoniem

20 aug 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.