Welcome to collectivesolver - Programming & Software Q&A with code examples. A website with trusted programming answers. All programs are tested and work.

Contact: aviboots(AT)netvision.net.il

Buy a domain name - Register cheap domain names from $0.99 - Namecheap

Scalable Hosting That Grows With You

Secure & Reliable Web Hosting, Free Domain, Free SSL, 1-Click WordPress Install, Expert 24/7 Support

Semrush - keyword research tool

Boost your online presence with premium web hosting and servers

Disclosure: My content contains affiliate links.

39,845 questions

51,766 answers

573 users

How to convert array strings into dictionary in VB.NET

2 Answers

0 votes
Module Module1

    Sub Main()

        Dim array() As String = {"VB.NET", "Java", "PHP", "C#", "C++"}

        Dim dic As Dictionary(Of String, Integer) = array.ToDictionary(Function(s As String)
                                                                           Return s
                                                                       End Function,
                                                                       Function(s As String)
                                                                           Return s.Length
                                                                       End Function)

        For Each item As KeyValuePair(Of String, Integer) In dic
            Console.WriteLine("{0} : {1}", item.Key, item.Value)
        Next

    End Sub

End Module

' run:
' 
' VB.NET : 6
' Java: 4
' PHP: 3
' C#: 2
' C++ :  3

 



answered Sep 27, 2018 by avibootz
0 votes
Module Module1

    Sub Main()

        Dim array() As String = {"VB.NET", "Java", "PHP", "C#", "C++"}

        Dim dic As New Dictionary(Of String, Integer)

        For i As Integer = 0 To array.Count - 1
            dic.Add(array(i), i + 1)
        Next

        For Each item As KeyValuePair(Of String, Integer) In dic
            Console.WriteLine("{0} : {1}", item.Key, item.Value)
        Next

    End Sub

End Module

' run:
' 
' VB.NET : 1
' Java: 2
' PHP: 3
' C#: 4
' C++ :  5

 



answered Sep 27, 2018 by avibootz
...