2012-04-29 3 views
0

아래 코드에는 CreatePage 함수에 thumbs라는 이름의 인라인 매개 변수가 있습니다. 엄지 손가락은 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 A와 방법의

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

자보세요!