2008-08-21 20 views
2

私はSystem.Generic.Collections.List(Of MyCustomClass)タイプのオブジェクトを持っています。Linqのない一般的なコレクション

整数とページサイズとページ番号を指定すると、どのようにしてMyCustomClassオブジェクトの1ページのみを収集できますか?

これは私が持っているものです。どうすれば改善できますか?

あなたのIEnuramble実装するコレクションにGetRangeを使用
'my given collection and paging parameters 
Dim AllOfMyCustomClassObjects As System.Collections.Generic.List(Of MyCustomClass) = GIVEN 
Dim pagesize As Integer = GIVEN 
Dim pagenumber As Integer = GIVEN 

'collect current page objects 
Dim PageObjects As New System.Collections.Generic.List(Of MyCustomClass) 
Dim objcount As Integer = 1 
For Each obj As MyCustomClass In AllOfMyCustomClassObjects 
If objcount > pagesize * (pagenumber - 1) And count <= pagesize * pagenumber Then 
    PageObjects.Add(obj) 
End If 
objcount = objcount + 1 
Next 

'find total page count 
Dim totalpages As Integer = CInt(Math.Floor(objcount/pagesize)) 
If objcount Mod pagesize > 0 Then 
totalpages = totalpages + 1 
End If 

答えて

1

:私はあなたがここから個々のページをつかむためにGetRangeを使用する方法を見つけ出すことができ、信頼

List<int> lolInts = new List<int>(); 

for (int i = 0; i <= 100; i++) 
{ 
    lolInts.Add(i); 
} 

List<int> page1 = lolInts.GetRange(0, 49); 
List<int> page2 = lilInts.GetRange(50, 100); 

2

あなたがこれを行うことができるようにGeneric.Listは、スキップを(提供)と()メソッドを取る必要があります:あなたは2.0 Frameworkを意味し、 "LINQのなし" による場合

Dim PageObjects As New System.Collections.Generic.List(Of MyCustomClass) 
PageObjects = AllOfMyCustomClassObjects.Skip(pagenumber * pagesize).Take(pagesize) 

を、IドンList(Of T)はこれらのメソッドをサポートしていると信じていません。その場合は、Jonathanの提案のようにGetRangeを使用してください。

関連する問題