+92 332 4229 857 99ProjectIdeas@Gmail.com

LINQ Except() Method (Vb.net)



The following code shows you how to take different values from two arrays.
For example you have array one = {0, 1, 3 , 2 , 4 ,5}  and array second = {1, 3 , 6 , 4 ,5 , 7}. Then through LINQ Except() method the output would be {0,2} because these two are not availabe in second array. See the code below.




Dim intArr As Integer() = {2, 1, 2, 3, 7, 5, 10, 9}

Dim intArr2 As Integer() = {3, 5, 7, 2, 7, 5, 11, 19}

   Dim query = intArr.Except(intArr2)

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

Output of the program is:
1 10 9 (because these three are different in intArr except others)

Or,

Dim intArr As Integer() = {2, 1, 2, 3, 7, 5, 10, 9}

Dim intArr2 As Integer() = {3, 5, 7, 2, 7, 5, 11, 19}

   Dim query = intArr2.Except(intArr)

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

Output of the program is:
11 19 (because these tow are different in intArr2 except others)

0 comments: