How to iterate a Dictionary(Of Integer, List(Of MyClass))

Hello  there,

I am experiencing some severe problems, when trying to iterate  a dictionary of type Dictionary(Of Integer, List (Of clsMyClass) ).

How can I access the list in a single Dictionary object ?

Public Sub TestMe()
        Dim EOL As String = vbCrLf

        Dim strText = System.IO.File.ReadAllText(_FileName)

        Dim _lines As String()
        _lines = Split(strText, EOL)

        Dim EDIFileReferences As New Dictionary(Of Integer, List(Of clsEDI_FileImportMappingClass))
        For row As Integer = 0 To _lines.Count - 1
            Dim line As String
            line = _lines(row)
            Dim SEGMDESC As String = Left(line, 3)
            Dim Filter As String = line.Substring(3, 2)
            Dim Mapping As List(Of clsEDI_FileImportMappingClass) = Profil.getEdiSegCols(SEGMDESC, Filter)
            Dim x As New List(Of clsEDI_FileImportMappingClass)
            x = MapContentsOfImportedEdiFile(line, Mapping)
            EDIFileReferences.Add(row, New List(Of clsEDI_FileImportMappingClass))
            EDIFileReferences(row) = x
		' (2) Following fragment is showing only identical contents:

        For row As Integer = 0 To EDIFileReferences.Count - 1

            Dim objList As List(Of clsEDI_FileImportMappingClass) = EDIFileReferences(row)
            Dim sout As String : sout = ""
            For x As Integer = 0 To EDIFileReferences(row).Count - 1
                sout = "ROW IN FILE: " & row.ToString & " | SEGMENT: " & EDIFileReferences(row).Item(x).SEGMENT & " | FELD-NR.:" & EDIFileReferences(row).Item(x).EDI_FIELD & " | CONTENTS: " & EDIFileReferences(row).Item(x).CONTENTS.ToString

End Sub

' *****************************************************

Public Function MapContentsOfImportedEdiFile(ByVal csvline As String, ByVal ediDBObjMapping As List(Of clsEDI_FileImportMappingClass)) As List(Of clsEDI_FileImportMappingClass)

        Dim x As New List(Of clsEDI_FileImportMappingClass)
        ' Processing ediDBObjMapping 

        ' Return mapped contents
        Return x
   End Function

Open in new window

Stephan DijkxhoornAsked:
Who is Participating?

[Product update] Infrastructure Analysis Tool is now available with Business Accounts.Learn More

I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

Pawan KumarDatabase ExpertCommented:
>>How to iterate a Dictionary
Sample LOOP for dictionary

Dim dictionars As New Dictionary(Of String, Integer)
        dictionars.Add("a", 1)
        dictionars.Add("b", 2)
        dictionars.Add("c", 3)
        dictionars.Add("d", 3)

 Dim pr As KeyValuePair(Of String, Integer)
        For Each pr In dictionars           
            Console.WriteLine("{0}, {1}", pr.Key, pr.Value)

Open in new window

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
Fernando SotoRetiredCommented:
Hi Stephan;

This is how to iterate through the List stored in the Dictionary object.
Dim myDictionary As New Dictionary(Of Integer, List(Of clsMyClass))
myDictionary.Add(1, mClass)

'' Get a List of clsMyClass from the Dictionary
Dim theList As List(Of clsMyClass) = myDictionary(1)
'' Iterate through the List of clsMyClass
For Each item As clsMyClass In theList
	Console.WriteLine("Name: {0} and Age: {1}", item.Name, item.Age)

Open in new window

Stephan DijkxhoornAuthor Commented:
I found a working solution and there was no connection to your answer, Fernando.
Fernando SotoRetiredCommented:
Hi Stephan;

The solution you selected does not even handle the case you gave in the question having a dictionary of in't list of objects we're mine does how come you selected that solution can you explain please.
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Visual Basic.NET

From novice to tech pro — start learning today.