如何在vb.net中将Dictionary.items分配给类对象

时间:2018-12-17 17:13:58

标签: vb.net vb6-migration

嗨,我正在将VB6迁移到vb.net,并计划将Scripting.Dictionary替换为Dictionary(Of String, clsAnimal)

下面的代码是vb6,它使用Dictionary

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

那么如何使用Dictionary(Of String, clsAnimal)在VB.Net中重写以上内容?

1 个答案:

答案 0 :(得分:2)

这是一个完整的示例:

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