Reputation:
How do I iterate through an IList collection and return only n number of records? I am trying to implement paging using an IList object.
Upvotes: 0
Views: 842
Reputation: 7146
foreach (int i in myList.Take(4))
{
// do some stuff
}
It's worth noting that for pagination, you'll also want some sort of offset. To do so, you could do the following as well:
foreach (int i in myList.Skip(40).Take(20)) { }
In C#.
Upvotes: 1
Reputation: 103740
Use the very useful PagedList:
http://blog.wekeroad.com/blog/aspnet-mvc-pagedlistt/
Upvotes: 2
Reputation: 6986
(From o As Object In myList).Take(n)
Hanselman has a good Paginated List class in his ASP .NET MVC tutorial here. You should check it out.
Upvotes: 1