I have a custom control with a data source of type IEnumerable (non-generic). Now I want to implement paging on the data source, and so I need something like Skip and Take, which List-of-T has. Right now I am using the following:
List<object> pagingList = DataSource.Cast<object>().ToList()
This can be inefficient, I’m guessing, so I’m looking for a better way to do this. Enumerating the collection, skipping elements and such with two counters might be more efficient, but it’s so ugly I just don’t want to do it. But maybe it’s the best choice?
Why are you calling
ToList()? You can useSkipandTakewithout that:That will save converting the whole data source to a list – but it does mean you can’t skip efficiently when the source isn’t an
IList<T>.Two important questions though: