List<> collections
-
I have 2 list collections as below List1 115 100 150 List2 115 100 now i need to check both of above list and need to get answer for matched , for example : 115 100 both matched, i need to achieve this how can i do it ?
See if this works for you ... Vote 5 if it does.
Dim listA, listB, listC As New List(Of Integer)
Dim i As IntegerlistA.Add(115) listA.Add(100) listA.Add(150) listB.Add(115) listB.Add(100) For i = 0 To listA.Count - 1 If (listB.Contains(listA(i))) Then listC.Add(listA(i)) End If Next For i = 0 To listC.Count - 1 Debug.Print("The following items are common to both lists: " & CStr(listC(i))) Next
-
See if this works for you ... Vote 5 if it does.
Dim listA, listB, listC As New List(Of Integer)
Dim i As IntegerlistA.Add(115) listA.Add(100) listA.Add(150) listB.Add(115) listB.Add(100) For i = 0 To listA.Count - 1 If (listB.Contains(listA(i))) Then listC.Add(listA(i)) End If Next For i = 0 To listC.Count - 1 Debug.Print("The following items are common to both lists: " & CStr(listC(i))) Next
-
List.Intersect[^] does this for you.
very cool. I'm living in the dark ages (.NET 2.0), so this feature was available. Good to know. :thumbsup:
-
See if this works for you ... Vote 5 if it does.
Dim listA, listB, listC As New List(Of Integer)
Dim i As IntegerlistA.Add(115) listA.Add(100) listA.Add(150) listB.Add(115) listB.Add(100) For i = 0 To listA.Count - 1 If (listB.Contains(listA(i))) Then listC.Add(listA(i)) End If Next For i = 0 To listC.Count - 1 Debug.Print("The following items are common to both lists: " & CStr(listC(i))) Next
-
very cool. I'm living in the dark ages (.NET 2.0), so this feature was available. Good to know. :thumbsup:
David Mujica wrote:
very cool.
I'm living in the dark ages (.NET 2.0), so this feature was available.:laugh: :laugh: :laugh: DARK AGES OF 2.0 HA HA HAAA
-
I have 2 list collections as below List1 115 100 150 List2 115 100 now i need to check both of above list and need to get answer for matched , for example : 115 100 both matched, i need to achieve this how can i do it ?
-
Try List.Intersect[^].
Cool indeed.. :thumbsup:
-
List.Intersect[^] does this for you.
Good answer!
Wonde Tadesse MCTS