I need to create a dictionary within a dictionary


I need to create a dictionary within a dictionary within VB.net

Declaration (I think) will be something like:

Dim DriverList As Dictionary(Of String, Dictionary(Of String, clsLapDetail)

I think...


What I want to do is create a Dictionary entry for each DriverID in my DriverList.

Now that I have a dictionary for each driver_ID, I need to populate my second dictionary with a key (To be determined) and details for each lap as a driver completes a lap.

clsDetail is defined in the atached code.

What I need specifically, is proper declaration of the dictionary within a dictionary (with the clsLapDetail)
and how to initially populate the initial, base entries.

Looking for VB.net syntax, please.

Thanks in advance.

'Declaration of clsLapDetail:

Public Class clsLapDetail
    Public Lap As Integer
    Public LapTime As Integer
    Public PassingTime As Integer
    Public ElapsedTime As Integer
    Public LapSpeed As Decimal
End Class

Open in new window

Who is Participating?
Jeff CertainConnect With a Mentor Commented:
Private DriverList As New Dictionary(Of String, Dictionary(Of String, clsLapDetail)
For Each id As String in DriverIdList
    DriverList.Add(id, New Dictionary(Of String, clsLapDetail))
indy500fanAuthor Commented:

I don't need to fill out values for the elements inside clsLapDetail for the initial entry?

Jeff CertainCommented:

That's just an empty dictionary until you start adding laps to it.

The syntax will be something like If DriverList.ContainsKey(id) Then DriverList(id).Add(lapId, lapDetail)
Cloud Class® Course: Microsoft Exchange Server

The MCTS: Microsoft Exchange Server 2010 certification validates your skills in supporting the maintenance and administration of the Exchange servers in an enterprise environment. Learn everything you need to know with this course.

indy500fanAuthor Commented:
Okay, I guess not, I just tried it.

Now I just need to figure out how to add to each driver's dictionary, lap detail.

New question coming soon.
indy500fanAuthor Commented:
Chaosian is a genius!
Jeff CertainCommented:
Not yet. LOL. Still 150K points to go before I get that designation around here. :)

Glad I could help.
indy500fanAuthor Commented:
Ha!  you already answered my next question with If DriverList.ContainsKey(id) Then DriverList(id).Add(lapId, lapDetail)

Thank you SO MUCH!
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.