Solved

VB.NET list to dictionnary

Posted on 2015-02-11
2
122 Views
Last Modified: 2015-02-11
Hello EE,

I got a list in vb.net  of strings

something like ;

01
3
02
9
03
1
04
0
05
5
06
8
07
1
08
1
etc...


it goes like that up to 100.  you see the pattern here.. actually its the number 01 to 100 and between them i have a value.
I would like to convert this to a dictionnary so that the key is the number 01 to 100 and the value is the value in between from the list...

can you help ?
thanks
0
Comment
Question by:PhilippeRenaud
2 Comments
 
LVL 75

Accepted Solution

by:
käµfm³d   👽 earned 500 total points
ID: 40604141
Honestly, I think spelling this out in an old-skool For loop would be the easiest to read and understand.

e.g.

Module Module1

    Sub Main()
        Dim originalList As New List(Of String) From
        {
            "01",
            "3",
            "02",
            "9",
            "03",
            "1",
            "04",
            "0",
            "05",
            "5",
            "06",
            "8",
            "07",
            "1",
            "08",
            "1"
        }
        Dim theDictionary As New Dictionary(Of String, String)()

        For i As Integer = 0 To originalList.Count - 1 Step 2
            theDictionary.Add(originalList(i), originalList(i + 1))
        Next

        System.Diagnostics.Debugger.Break()
    End Sub

End Module

Open in new window

0
 
LVL 1

Author Closing Comment

by:PhilippeRenaud
ID: 40604152
Yup, I just thought to that and was about to delete my question haha.

Thank you Kaufmed =)
0

Featured Post

Master Your Team's Linux and Cloud Stack

Come see why top tech companies like Mailchimp and Media Temple use Linux Academy to build their employee training programs.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Today I had a very interesting conundrum that had to get solved quickly. Needless to say, it wasn't resolved quickly because when we needed it we were very rushed, but as soon as the conference call was over and I took a step back I saw the correct …
Calculating holidays and working days is a function that is often needed yet it is not one found within the Framework. This article presents one approach to building a working-day calculator for use in .NET.

830 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