.NET - I want to do this: Dim D as new Dictionary(of String, Array(OF MYOBJECT))
-
06-07-2019 - |
Question
I'd like to create a Dictionary that is indexed by Strings: Dictionary(of String, ...)
I'd like the Type after the comma to be an Array of MyObject's.
If all I do is the following:
Dim D as new Dictionary(of String, Array)
I feel like I'm missing out on some performance very time I access a member:
Dim Object1 as MyObject = MyDictionary("Key1")(4)
Doesn't it have to perform some type of lookup to figure out what type of object the array is holding every time I access it in this manner?
Solution
Array
isn’t what you want; rather, use the strongly typed array that you want to have:
Dim D as New Dictionary(Of String, MyObject())()
This works like a charm.
OTHER TIPS
If the Value really needs to be an array of MyObject, you could do the following:
Dim D as new Dictionary(of String, MyObject())
Using array, you will be invoking type casting when you retrieve it. How about this:
Dim D as new Dictionary(of String, List(of MyObject))
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow