VB Collections in .NET

G

Guest

I have read that Abstract Data Types such as ArrayList, Queue, SortedList and
HashTable are intended to eventually replace the old VB Collection class.
However, I have yet to find a .NET type which lets you add key/value pairs
and, at the same time, keep the values in the same order in which they were
original added (the way the old collection did). For example, suppose I
inherit a class from DictationaryBase and do something like the following:

mydict as mydictionary = new mydictionary()
for i as integer = 1 to 3
mydict.add(i.tostring, i)
dim de as DictationaryEntry
for each de in mydict
debug.writeline de.value
next

The output is:
2
3
1

How do I set up a .NET collection which would output 1 2 3, the way I want?
Or do I just continue using the "old fashioned" VB Collection?

Dan
 
G

Guest

Actually, on further research, the .NET implementation of the original VB
collection doesn't enumerate in the proper order either. However, in VB6,
the following code will output the items in the order they were put in:

Sub MySub()
Dim col As New Collection
Dim i As Integer
For i = 1 To 3
col.Add i, CStr(i)
Next
Dim v
For Each v In col
Debug.Print v
Next
End Sub
 
G

Guest

Dan,

Will the NameObjectCollectionBase class in the
System.Collections.Specialized namespace allow you to build the type of
collection that you need?

Kerry Moorman
 
G

Guest

Thanks very much Cor and Kerry.

Actually Kerry did suggest the right class. The CollectionBase's IList.Add
method only allows you to add an object without specifying your own index. I
need to be able to specify and index.

Again, thank you both very much! It was a big help.

Dan
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top