A list with key-value pairs sorted by adding sequence?

Hello,

i need a key-value pair list sorted by adding sequence like a collection. But i see that the Dictionary Class, the HashTable Class, the Sorted List Class seem not to do that.
Must i use two Collections one with the keys a second with the values for that, or does such a list exist

Regards,

Markus



Answer this question

A list with key-value pairs sorted by adding sequence?

  • Nico_M

  • Marjorie

    What your probably looking for is a sorteddictionary collection which is avaialble in VB2005

    Sorted Disctionary Class
    http://msdn2.microsoft.com/en-us/library/f7fta44c.aspx

    This represents a collection of key/value pairs that are sorted on the key.


  • flash.tato

    > To clarify, you need a key and a value but you want things sorted by the order in which they were added
    > to the list, not on the key or the value

    Yes.

    > If so, you could just use a List.

    Or a collection. What is the difference

    Thank you for your answer!
    Then i think there is really no key-value pair list sorted in my requested order.


  • grblev

    Thank you Deborah for the link.

    Spotty wrotes:
    > This represents a collection of key/value pairs that are sorted on the key.

    I want it in the order in which they where added to the list. How Deborah writes it is not much work to get such list by using a list or a collection and creating a own class with the key/value pair.


  • Astek djacquet

    Oh i see in the help of vb.net that the list class is not guaranteed to be sorted.

    I want to have a ordered list but not a sorted list.

    So my question is again:
    Is the old good collection the only list that is sorted in the sequence elements where added


  • Voodoo45

    To clarify, you need a key and a value but you want things sorted by the order in which they were added to the list, not on the key or the value

    If so, you could just use a List. This will allow you to access the data in sequential order. Then create a class with a property for the name and value and put instances of the class in the List.

    hope this helps ...


  • A list with key-value pairs sorted by adding sequence?