# In VB.Net: Retrieve values from a SortedList



## Neophyte Nerd (Oct 4, 2007)

I have a SortedList in a VB.Net program I'm writing. (SortedLists are one of the many special types of arrays one can have in VB.Net.) The list has Keys and Values, always sorted by the Keys. (It contains Roman numerals from a text as keys, and the values assigned to the keys are the frequency of appearance of those Roman numerals in the original text.)

I want to find the value (i.e., number of appearances) of the key "I". If the original text is not in English, "I" will have a low frequency and will really be a Roman numeral. If the text is in English and "I" has many occurrences, then it probably is a subject pronoun and not a Roman numeral. I don't know how to tell if a text is in English, but I can certainly compare the frequency of "I" compared to the number of different words in a text and deduce from that whether "I" is an English word or a Roman numeral.

How can I find out the value assigned to the key "I" in the SortedList? The only way I could think of is to go through the list item by item and when an entry has the key "I", then get its value (frequency of appearance). 

Any help anyone can give is most welcome.

Neophyte Nerd
Priddis, Alberta


----------



## artur02 (Sep 24, 2007)

Check this article: http://msdn2.microsoft.com/en-us/library/system.collections.sortedlist.aspx

The important part for you is:

```
For i = 0 To myList.Count - 1
            Console.WriteLine(ControlChars.Tab & "{0}:" & ControlChars.Tab & _
               "{1}", [B]myList.GetKey(i), myList.GetByIndex(i)[/B])
        Next i
```


----------



## Neophyte Nerd (Oct 4, 2007)

Artur02's code solves my problem. With grateful thanks I can now say that this matter is closed.
Neophyte Nerd
Priddis, Alberta, Canada


----------

