IndexedDictionary. Access a dictionary using item index.
.NET Dictionary object can hold a collection of keys and values. It allows you to iterate through these values using enumeration and you can also retrieve a value by using it's associated key.
But what if you want to create a collection of items and access them both using their associated key or numeric index in the collection? I created a VB.NET class that I named IndexedDictionary that does exactly that.
The class implements the generic IDictionary interface. Internally it contains an instance of a generic dicrtionary and also an instance of a List which holds the numeric position of each element in the dictionary.
Here is an example on how to use this:
1: Dim myData As New IndexedDictionary(Of String, String)
2: myData.Add("key0", "item0")3: myData.Add("key1", "item1")4:
5: Console.WriteLine(myData(1)) ' returns 'item1'
6: Console.WriteLine(myData("key1")) ' returns 'item1'
