I need to create a dictionary within a dictionary

Posted on 2011-05-07
Last Modified: 2012-08-14

I need to create a dictionary within a dictionary within

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 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

Question by:indy500fan
    LVL 24

    Accepted Solution

    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))

    Author Comment


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

    LVL 24

    Expert Comment

    by:Jeff Certain

    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)

    Author Comment

    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.

    Author Closing Comment

    Chaosian is a genius!
    LVL 24

    Expert Comment

    by:Jeff Certain
    Not yet. LOL. Still 150K points to go before I get that designation around here. :)

    Glad I could help.

    Author Comment

    Ha!  you already answered my next question with If DriverList.ContainsKey(id) Then DriverList(id).Add(lapId, lapDetail)

    Thank you SO MUCH!

    Write Comment

    Please enter a first name

    Please enter a last name

    We will never share this with anyone.

    Featured Post

    How to run any project with ease

    Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
    - Combine task lists, docs, spreadsheets, and chat in one
    - View and edit from mobile/offline
    - Cut down on emails

    This article explains how to create and use a custom WaterMark textbox class.  The custom WaterMark textbox class allows you to set the WaterMark Background Color and WaterMark text at design time.   IMAGE OF WATERMARKS STEPS Create VB …
    It’s quite interesting for me as I worked with Excel using for some time. Here are some topics which I know want to share with others whom this might help. First of all if you are working with Excel then you need to Download the Following …
    Migrating to Microsoft Office 365 is becoming increasingly popular for organizations both large and small. If you have made the leap to Microsoft’s cloud platform, you know that you will need to create a corporate email signature for your Office 365…
    Sending a Secure fax is easy with eFax Corporate ( First, Just open a new email message.  In the To field, type your recipient's fax number You can even send a secure international fax — just include t…

    737 members asked questions and received personalized solutions in the past 7 days.

    Join the community of 500,000 technology professionals and ask your questions.

    Join & Ask a Question

    Need Help in Real-Time?

    Connect with top rated Experts

    22 Experts available now in Live!

    Get 1:1 Help Now