How to check if 2 lists are identical in VB.NET

2 Answers

0 votes
Imports System
Imports System.Linq
Imports System.Collections.Generic

Public Class Program
	Public Shared Sub Main()
        Dim list1 As List(Of String) = New List(Of String)() From {
            "A",
            "B",
            "C",
            "D",
            "A"
        }
        Dim list2 As List(Of String) = New List(Of String)() From {
            "A",
            "B",
            "C",
            "D",
            "A"
        }
		
        Dim result As Boolean = list1.All(AddressOf list2.Contains) AndAlso list2.All(AddressOf list1.Contains)
		
        Console.WriteLine(result)
    End Sub
End Class




' run:
'
' True
'

 



answered Jul 29, 2023 by avibootz
0 votes
Imports System
Imports System.Linq
Imports System.Collections.Generic

Public Class Program
	Public Shared Sub Main()
        Dim list1 As List(Of String) = New List(Of String)() From {
            "A",
            "B",
            "C",
            "D",
            "A"
        }
        Dim list2 As List(Of String) = New List(Of String)() From {
            "A",
            "B",
            "C",
            "D",
            "A"
        }
		
        Dim result As Boolean = list1.SequenceEqual(list2)
		
        Console.WriteLine(result)
    End Sub
End Class




' run:
'
' True
'

 



answered Jul 29, 2023 by avibootz
...