×

VB.Net Programs

VB.Net program to demonstrate the Except() LINQ extension method

By Nidhi Last Updated : November 11, 2024

VB.Net – Except() LINQ Extension Method

In this program, we will use Except() method. This method requires two collections. It returns a new collection with elements from the first collection which do not exist in the second collection.

Program/Source Code:

The source code to demonstrate the Except() LINQ extension method is given below. The given program is compiled and executed successfully.

VB.Net code to demonstrate the example of Except() LINQ extension method

'VB.NET program to demonstrate the 
'Except() LINQ extension method.

Module Module1
    Sub Main()
        Dim intList1 = New List(Of Integer) From {101, 102, 103, 104, 105, 106}
        Dim intList2 = New List(Of Integer) From {103, 104, 105, 106}

        Dim result = intList1.Except(intList2)

        Console.WriteLine("Results:")
        For i = 0 To result.Count() - 1 Step 1
            Console.Write(result.ElementAt(i) & " ")
        Next
        Console.WriteLine()
    End Sub
End Module

Output

Results:
101 102
Press any key to continue . . .

Explanation

In the above program, we created a module Module1 that contains a Main() function. The Main() function is the entry point for the program.

In the Main() function, We used Except() LINQ extension method. This method requires two collections. It returns a new collection with elements from the first collection which do not exist in the second collection. After that, we printed the resulted collection on the console screen.

VB.Net LINQ Query Programs »


Comments and Discussions!

Load comments ↻





Copyright © 2024 www.includehelp.com. All rights reserved.