Concatenate List(Of T) with Func Delegate
الكود التالي يوضح كيف نضيف مصفوفة إلي مصفوفة أخري
Public Function ConcatenateList(Of T)(first As List(Of T), second As List(Of T)) As T()
Dim concatenate As Func(Of List(Of T), List(Of T), T()) = Function(X As List(Of T), Y As List(Of T))
Dim result As T() = New T(X.Count + Y.Count - 1) {}
For i As Integer = 0 To X.Count - 1
result(i) = X(i)
Next
For j As Integer = 0 To Y.Count - 1
result(X.Count + j) = Y(j)
Next
Return result
End Function
Return concatenate(first, second)
End Function
Usage:
' Use it as string list
Dim
l1 As List(Of String) = New List(Of String) From {"Omar", "Amr"}
Dim
l2 As List(Of String) = New List(Of String) From {"Sherief", "Ahmed", "Omar"}
' do something with the array
Dim
l3 As String() = ConcatenateList(Of String)(l1, l2)
ListBox1.Items.AddRange(l3)
' ---------------------------------------------------
' Use it as integer list
Dim
int1 As List(Of Integer) = New List(Of Integer) From {10, 20, 30}
Dim
int2 As List(Of Integer) = New List(Of Integer) From {40, 50, 60}
Dim
int3 As Integer() = ConcatenateList(Of Integer)(int1, int2)
' do something with the array
For
Each i As Integer In int3
ListBox2.Items.Add(i)
Next
Comments
Post a Comment