Solved

VB.NET list to dictionnary

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

DevOps Toolchain Recommendations

Read this Gartner Research Note and discover how your IT organization can automate and optimize DevOps processes using a toolchain architecture.

Question has a verified solution.

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

Entity Framework is a powerful tool to help you interact with the DataBase but still doesn't help much when we have a Stored Procedure that returns more than one resultset. The solution takes some of out-of-the-box thinking; read on!
Performance in games development is paramount: every microsecond counts to be able to do everything in less than 33ms (aiming at 16ms). C# foreach statement is one of the worst performance killers, and here I explain why.
This video shows how to quickly and easily add an email signature for all users on Exchange 2016. The resulting signature is applied on a server level by Exchange Online. The email signature template has been downloaded from: www.mail-signatures…

831 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