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

Here, we are going to demonstrate the SequenceEqual() LINQ extension method in VB.Net.
Submitted by Nidhi, on February 02, 2021 [Last updated : March 08, 2023]

VB.Net – SequenceEqual() LINQ Extension Method

In this program, we will use SequenceEqual() LINQ extension method to compare the element sequence of two lists. If the sequence of elements in both lists is the same then it will return true otherwise it will false value to the calling method.

Program/Source Code:

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

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

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

Imports System
Imports System.IO
Imports System.Linq

Module Module1
    Sub Main()
        Dim ret As Boolean = False

        Dim List1 As New List(Of String)
        List1.Add("ABC")
        List1.Add("DEF")
        List1.Add("GHI")
        List1.Add("JKL")

        Dim List2 As New List(Of String)
        List2.Add("ABC")
        List2.Add("DEF")
        List2.Add("GHI")
        List2.Add("JKL")

        Dim List3 As New List(Of String)
        List3.Add("DEF")
        List3.Add("ABC")
        List3.Add("GHI")
        List3.Add("JKL")

        ret = List1.SequenceEqual(List2)
        If ret = True Then
            Console.WriteLine("Element Sequence of both lists are same")
        Else
            Console.WriteLine("Element Sequence of both lists are not same")
        End If

        ret = List1.SequenceEqual(List3)
        If ret = True Then
            Console.WriteLine("Element Sequence of both lists are same")
        Else
            Console.WriteLine("Element Sequence of both lists are not same")
        End If
    End Sub
End Module

Output

Element Sequence of both lists are same
Element Sequence of both lists are not same
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 created three lists List1, List2, and List3. Here, we added the string elements to all lists. After we checked the sequence of list elements and print the appropriate message on the console screen.

VB.Net LINQ Query Programs »






Comments and Discussions!

Load comments ↻






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