+92 332 4229 857 99ProjectIdeas@Gmail.com

LINQ Union() Method (Vb.net)



The following code shows you how to union two arrays.. for example arrayOne contains {1,2,3,4,2} and arrayTwo contains {2,4,5,1,2} then after applying LINQ Union() method you will get a output like this {2, 4, 5 1, 3}. Why this if you take general idea the output would be this: {1,2,3,4,2,2,4,5,1,3}. But Union() method omits out the repeating elements from array and considered them single entry. See the code below.




Dim number1() As Integer = {6, 8, 9, 5, 7}

Dim number2() As Integer = {1, 19, 35, 7, 2, 6}

Dim query = number1.Union(number2)

        For Each i In query
            Console.Write(i & " ")
        Next

Output of the program is:
6 8 9 5 7 1 19 35 2 (you see 6 and 7 are repeating but here considered as one entry)


0 comments: