Search code examples
vb.netvb6-migration

how to assign Dictionary.items to a class object in vb.net


Hi I am migrating VB6 to vb.net and planning to replace Scripting.Dictionary with Dictionary(Of String, clsAnimal).

The below code is vb6 which uses a Dictionary

   Dim clsAni As clsAnimal '(This is a class object)
   Dim test As String
   Set clsAni = m_dicDemographics.Item(test)

So how can I rewrite the above in VB.Net using Dictionary(Of String, clsAnimal)?


Solution

  • Here's a complete sample:

    Public Class clsAnimal  
        ' Members go here.
    End Class
    
    Module Module1
        Dim m_dicDemographics As Dictionary(Of String, clsAnimal) = New Dictionary(Of String, clsAnimal)
    
    Sub Main()
        m_dicDemographics.Add("Frog", New clsAnimal())
        Dim clsAni As clsAnimal = m_dicDemographics.Item("Frog")
    End Sub
    
    End Module