code_junkie

How do I page a generic collection without Linq?

Nov 10th, 2011
132
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.02 KB | None | 0 0
  1. 'my given collection and paging parameters
  2. Dim AllOfMyCustomClassObjects As System.Collections.Generic.List(Of MyCustomClass) = GIVEN
  3. Dim pagesize As Integer = GIVEN
  4. Dim pagenumber As Integer = GIVEN
  5.  
  6. 'collect current page objects
  7. Dim PageObjects As New System.Collections.Generic.List(Of MyCustomClass)
  8. Dim objcount As Integer = 1
  9. For Each obj As MyCustomClass In AllOfMyCustomClassObjects
  10. If objcount > pagesize * (pagenumber - 1) And count <= pagesize * pagenumber Then
  11. PageObjects.Add(obj)
  12. End If
  13. objcount = objcount + 1
  14. Next
  15.  
  16. 'find total page count
  17. Dim totalpages As Integer = CInt(Math.Floor(objcount / pagesize))
  18. If objcount Mod pagesize > 0 Then
  19. totalpages = totalpages + 1
  20. End If
  21.  
  22. Dim PageObjects As New System.Collections.Generic.List(Of MyCustomClass)
  23. PageObjects = AllOfMyCustomClassObjects.Skip(pagenumber * pagesize).Take(pagesize)
  24.  
  25. List<int> lolInts = new List<int>();
  26.  
  27. for (int i = 0; i <= 100; i++)
  28. {
  29. lolInts.Add(i);
  30. }
  31.  
  32. List<int> page1 = lolInts.GetRange(0, 49);
  33. List<int> page2 = lilInts.GetRange(50, 100);
Add Comment
Please, Sign In to add comment