I am coding on VB.net . I'like to compare 2list and find not matching items. But my code looks for only the first list items so it doesn't check if there is missing.
I will use Serie_Code
in my comprasion .
SelectedItems is a List Of String,
SeriConrolList is a List:
Private Property SeriControlList As List(Of SeriRow)
Get
If Session("SeriControlList") Is Nothing Then
Session("SeriControlList") = New List(Of SeriRow)
End If
Return Session("SeriControlList")
End Get
Set(value As List(Of SeriRow))
Session("SeriControlList") = value
End Set
End Property
And this is how SeriRow:
Private Class SeriRow
Public Serie_Code As String = String.Empty
Public Serie_Name As String = String.Empty
Public Serie_Name_Eng As String = String.Empty
Public Frequency As String = String.Empty
Public Behaviour As String = String.Empty
Public Summable As Integer = 0
Public Data_Source As String = String.Empty
Public Data_Source_Eng As String = String.Empty
Public Start_Date As Date? = Nothing
Public End_Date As Date? = Nothing
End Class
SeriControlList has 28items.
SelectedItems has 26items.
Dim hash As HashSet(Of String) = New HashSet(Of String)(SeriControlList.Select(Function(x) x.Serie_Code.Replace("_", ".")))
Dim Result = (SelectedItems.Where(Function(x) Not hash.Contains(x.ToString))).ToList
I've also tried this:
Dim TupleAdd = (From nt In SeriControlList Where Not SelectedItems.Any(Function(n) Not nt.Serie_Code.Replace("_", ".") = n) _
Select nt.Serie_Code, nt.Serie_Name, nt.Serie_Name_Eng, nt.Frequency, nt.Start_Date, nt.End_Date, _
nt.Behaviour, nt.Data_Source, nt.Data_Source_Eng, nt.Summable).ToList
Also tried to reverse of this comparison. There's 2missing items and they return just 0.
Thank you
EDIT: I did it as the following and works fine:
For i = 0 To Me.SeriControlList.Count - 1
If Not SelectedItems.Contains(SeriControlList(i).Serie_Code.Replace("_", ".")) Then
Tuple = New SeriRow
Tuple.Serie_Code = Me.SeriControlList(i).Serie_Code
Tuple.Serie_Name = Me.SeriControlList(i).Serie_Name
Tuple.Serie_Name_Eng = Me.SeriControlList(i).Serie_Name_Eng
Tuple.Start_Date = Me.SeriControlList(i).Start_Date
Tuple.End_Date = Me.SeriControlList(i).End_Date
Tuple.Frequency = Me.SeriControlList(i).Frequency
Tuple.Summable = Me.SeriControlList(i).Summable
Tuple.Behaviour = Me.SeriControlList(i).Behaviour
Me.TCMBtoVRMT.Add(Tuple)
End If
Next