The .net runtime is exposed to VBA (and other COM clients) via mscorlib.dll. In theory, VBA can consume .net HashTables. In practice I am stuck. I have commented out lines that themselves don't work. The simple use case is iterating over the keys as I would for a Scripting.Dictionary
Function GenerateSampleHashTable() As Object
Dim ht As Object
Set ht = CreateObject("System.Collections.HashTable")
ht.Add "Foo", "Bar"
ht.Add "Red", "FF0000"
ht.Add "Green", "00FF00"
ht.Add "Blue", "0000FF"
Set GenerateSampleHashTable = ht
End Function
Sub TestHashTable()
Dim ht As Object
'*** PRETEND THIS CAME OUT OF A C# COMPONENT ***
Set ht = GenerateSampleHashTable
Debug.Print ht.ContainsKey("Foo")
Dim oKeys As Object
Set oKeys = CreateObject("System.Collections.ArrayList")
oKeys.Capacity = ht.Count
Dim vKeys() As Variant
vKeys() = oKeys.ToArray()
Dim col As mscorlib.ICollection
Set col = ht.Keys()
'col.CopyTo oKeys, 0 'Runtime error: Type mismatch
'col.CopyTo vKeys(), 0 'Compile Error: Type mismatch
Dim vKeyLoop As Variant
For Each vKeyLoop In vKeys()
Debug.Print vKeyLoop, ht.Item(vKeyLoop)
Next
End Sub