Snoopy Ohoo
Snoopy Ohoo

Reputation: 109

vb.net combine to array with the same range

if i have an array like this

A
B
C
D
E

and a second array like this

A
B
C
D
E

how to creat new array from the first tow arrays so the new array be like this

AA
BB
CC
DD
EE

i try this

 Dim urls() As String
    For i As Int32 = 0 To array1.Length - 1
        urls = array1.Select(Function(o) array2(i) & o).ToArray()
 next

but the output was like this

EA
EB
EC
ED
EE

Upvotes: 0

Views: 80

Answers (2)

User9995555
User9995555

Reputation: 1556

Try this...

    Dim array1() As String = {"A", "B", "C", "D", "E"}
    Dim array2() As String = {"A", "B", "C", "D", "E"}


    Dim urls() As String
    urls = array1.Select(Function(o, p) o & array2(p)).ToArray()

Hope that helps....

Upvotes: 1

Akshay G
Akshay G

Reputation: 2280

you are using for loop and lambda query both which shouldn't be the case. Try the below code

Dim urls() As String
urls = array1.Select(Function(item, index) item & array2(index)).ToArray()

OR

Dim urls() As String
urls = array1.Zip(array2, Function(x, y) x & y).ToArray()

Upvotes: 2

Related Questions