+92 332 4229 857 99ProjectIdeas@Gmail.com

LINQ Zip() Method (Vb.net)



The following code shows you how to add elements of two arrays parallel. for example firstArray{2,3,4,1,5} and secodArray {1, 2 ,3 , 4 , 5} then after LINQ Zip() method the output would be {3,5,7,5,10}. Although you can do through loop but it is lengthy method. Here is the code below...






Dim numb() As Integer = {2, 1, 2, 3, 7, 5, 10, 9}
Dim numb2() As Integer = {3, 5, 7, 2, 7, 5, 11, 19}

Dim query = numb.Zip(numb2, Function(firstArrVal, secondArrVal) firstArrVal + secondArrVal)

   For Each item In query
        Console.Write(item)
   Next

Output of the program is:
5 6 9 5 14 10 21 28 

Concatenates two arrays parallel Through Zip() method 

Dim numb() As Integer = {1, 2, 3, 4, 5}
Dim words() As String = {"one", "two", "three", "four", "five"}

Dim query = numb.Zip(words, Function(firstArrVal, secondArrVal) firstArrVal & " " & secondArrVal)

        For Each item In query
            Console.WriteLine(item)
        Next

Output of the program is:
1 one
2 two 
3 three
4 four
5 five 

see this in c#.net 

0 comments: