List Group

shers

Well-known member
Joined
Aug 12, 2007
Messages
86
Programming Experience
1-3
Hi,

I have a collection of (String, Integer). I have taken it into a String() Array and then added to a List(Of String()). I then need to find the duplicates in this list and if found, then add up the corresponding integers. How do I do this? Am I using the right Collection? If not which one would be the best?

Thanks
 
Hi,
Im not sure about how your list are formated. If you can display a sample of the data then it should only take a minute.

Later.
 
It sounds like a Dictionary(Of String, List(Of Integer)) would be the appropriate data structure. The Dictionary has String keys and each key has a list of Integers associated with it.
 
Imports System.Collections.Generic

Public Class Form1

    Dim Mydictionary As New Dictionary(Of String, List(Of Integer))

    Private Sub ShowListing(ByVal sListName As String)
        Dim Mylist As List(Of Integer) = Mydictionary(sListName)
        Dim s As String = ""

        For Each elem As Integer In Mylist
            s += elem.ToString & vbCrLf
        Next

        MsgBox(s)
    End Sub

    Private Sub Form1_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
        Dim tList1 As New List(Of Integer)
        Dim tList2 As New List(Of Integer)

        With tList1
            .Add(10)
            .Add(20)
            .Add(30)
            .Add(40)
            .Add(50)
        End With

        Mydictionary.Add("List 1", tList1)

        With tList2
            .Add(100)
            .Add(200)
            .Add(300)
            .Add(400)
            .Add(500)
        End With

        Mydictionary.Add("List 2", tList2)

        ShowListing("List 1")
        ShowListing("List 2")
    End Sub
End Class
 
Last edited by a moderator:
Back
Top