2012-04-29 10 views
0

下のコードには、CreatePage関数の親指という名前のインパラメータがあります。親指はarraylistです。私の質問は、arraylistの親指を15の部分に分割し、親指(1-15)、親指(16-30)、親指(31-45)などで関数を呼び出すことができるかどうかを知っている場合です。 arraylistが空になるまで。全てのVB.NETのArraylist

html.CreatePage(txtTitleTag.Text, txtText.Text, "index", txtDirectory.Text & "\", thumbs, txtMetaDesc.Text, txtMetaKeywords.Text, "test.com", "test2.com", BackgroundColor, FontColor) 
+0

使用している.NETのバージョンは何ですか?それが1.1ではない(本当にそれが疑わしい)なら、あなたは 'ArrayList'を使うべきではありません。 – Ryan

+0

.NET 4.0を使用しています –

+0

'ArrayList'にはどのような種類のオブジェクトがありますか? '文字列'ですか? – Ryan

答えて

1

まず、List(Of String)からArrayListからスイッチ。 ArrayListは既に.NET 2.0では時代遅れとなっています。強力なタイピングによって多くのメリットがあります。

<System.Runtime.CompilerServices.Extension()> 
Public Function Chunk(Of T)(ByVal this As List(Of T), ByVal length As Integer) As List(Of List(Of T)) 
    Dim result As New List(Of List(Of T)) 
    Dim current As New List(Of T) 

    For Each x As T In this 
     current.Add(x) 

     If current.Count = length Then 
      result.Add(current) 
      current = New List(Of T) 
     End If 
    Next 

    If current.Count > 0 Then result.Add(current) 

    Return result 
End Function 

は今、ちょうどFor Eachループを使用しているチャンクを反復:

次に、ここでチャンクListの方法だ

For Each chunk As List(Of String) In myList.Chunk(15) 
    'Call the function and pass chunk as an argument 
Next 

ほら!