Xojo.Core.Dictionary
From Xojo Documentation
The Dictionary class is an unordered, mutable, key-value store that is loosely typed. It implements the Iterable interface, allowing efficient and easy iteration over all key-value pairs.
Events | |
|
Properties | |
|
Methods | |||||||
|
Notes
As shown on GetIterator, if you change the Dictionary while iterating over it using For Each...Next, an exception will be raised. If you find you need to iterate and change the data, you can add a method to get all the keys into an array and then iterate through the array to access the Dictionary values. A method could be something like this:
Var results() As Auto
For Each item As Auto In obj
results.Append(item)
Next
Return results
End Function
Now you can call the method to get an array where you can then modify the contents:
' Stuff that can mutate the dictionary
Next
Sample Code
Add items to a Dictionary and loop through them:
months.Value("January") = 31
months.Value("February") = 28
months.Value("March") = 31
months.Value("April") = 30
months.Value("May") = 31
months.Value("June") = 30
months.Value("July") = 31
months.Value("August") = 31
months.Value("September") = 30
months.Value("October") = 31
months.Value("November") = 30
months.Value("December") = 31
For Each days As Xojo.Core.DictionaryEntry In months
Var numDays As Integer = days.Value
Next
See Also
Auto data type; Xojo.Core.DictionaryEntry, KeyNotFoundException, Dictionary classes