Tutorial :Iterate through an IList



Question:

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.


Solution:1

Use the very useful PagedList:

http://blog.wekeroad.com/blog/aspnet-mvc-pagedlistt/


Solution:2

(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.


Solution:3

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#.


Note:If u also have question or solution just comment us below or mail us on toontricks1994@gmail.com
Previous
Next Post »