Solved

VB.NET list to dictionnary

Posted on 2015-02-11
2
119 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 74

Accepted Solution

by:
käµfm³d   👽 earned 500 total points
Comment Utility
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
Comment Utility
Yup, I just thought to that and was about to delete my question haha.

Thank you Kaufmed =)
0

Featured Post

Threat Intelligence Starter Resources

Integrating threat intelligence can be challenging, and not all companies are ready. These resources can help you build awareness and prepare for defense.

Join & Write a Comment

Wouldn’t it be nice if you could test whether an element is contained in an array by using a Contains method just like the one available on List objects? Wouldn’t it be good if you could write code like this? (CODE) In .NET 3.5, this is possible…
Real-time is more about the business, not the technology. In day-to-day life, to make real-time decisions like buying or investing, business needs the latest information(e.g. Gold Rate/Stock Rate). Unlike traditional days, you need not wait for a fe…
Internet Business Fax to Email Made Easy - With eFax Corporate (http://www.enterprise.efax.com), you'll receive a dedicated online fax number, which is used the same way as a typical analog fax number. You'll receive secure faxes in your email, fr…
Illustrator's Shape Builder tool will let you combine shapes visually and interactively. This video shows the Mac version, but the tool works the same way in Windows. To follow along with this video, you can draw your own shapes or download the file…

771 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

9 Experts available now in Live!

Get 1:1 Help Now