Dictionary.Keys

From Xojo Documentation

Revision as of 12:15, 15 March 2021 by PLefebvre (talk | contribs) (Sample Code: Fixed typo)
(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)
Method

Dictionary.Keys() As Variant()

Supported for all project types and targets.

Returns all the keys in the Dictionary as an array of Variants.

Notes

The order is stable and matches the order returned by the Values method at least until the Dictionary is modified. Use this method with For Each or For...Next to loop through all the keys. Keys are not case-sensitive, but they are encoding-sensitive.

Sample Code

Suppose you have a Dictionary wordCounts whose keys are words, and whose values are the number of occurrences of the key in some text. You can produce a list of words sorted by count as follows.

Var word() As String
Var count() As Integer

For Each key As Variant In wordCounts.Keys
word.Add(key)
count.Add(wordCounts.Value(key))
Next
count.SortWith(word)