Determine if the two lists are equal : SequenceEqual « LINQ « VB.Net






Determine if the two lists are equal

 
Imports System
Imports System.Linq
Imports System.Collections.Generic

    Class Pet
        Public Name As String
        Public Age As Integer
    End Class


Public Class Example

    Public Shared Sub Main() 

        Dim pet1 As New Pet With {.Name = "Turbo", .Age = 2}
        Dim pet2 As New Pet With {.Name = "Peanut", .Age = 8}

        Dim pets1 As New List(Of Pet)()
        pets1.Add(pet1)
        pets1.Add(pet2)

        Dim pets2 As New List(Of Pet)()
        pets2.Add(New Pet With {.Name = "Turbo", .Age = 2})
        pets2.Add(New Pet With {.Name = "Peanut", .Age = 8})

        
        Dim equal As Boolean = pets1.SequenceEqual(pets2)

        Console.WriteLine(equal)

    End Sub
End Class

   
  








Related examples in the same category

1.Using SequenceEqual to see if two sequences match on all elements in the same order
2.Use SequenceEqual to compare two Arrays