Tutorial
Using mdTypes [EN]
von MOD | Seite 2 von 12 |
mdMap is the default key value store. You normaly wouldn't use the inner class mdMapEntry, except for the mdMap method entrySet(), with will return a mdSet of mdMapEntries.
mdDictionary and mdHashtable are almost the same like mdMap.
mdProperties is a extended map, but the key and value types are always Strings. (This class is not fully implemented yet.)
The declaration is pretty similar to list types. Here we have an example:
#Include Once "md/util/mdMap.bi"
mdMapDeclare(String, String)
Dim As mdMap(String, String) map
Dim As String temp
temp = map.put("key1", "value1")
temp = map.put("key2", "value2")
temp = map.put("key3", "value3")
Dim As mdSet(String) set = map.keySet()
Dim As String element
ForEach(String, element In set)
Print "key: " & element & " - value: " & map.get(element)
NextEach
Sleep
Because put() always returns the current value or, if the key already exists in the map, the old value for this key, I'm using here a temporary String. As of FreeBASIC 0.91 you don't need this, because you can ignore all function returns.
Of course, the same rules are given for maps like for lists. You can use all types except Integer, pointer types and your own classes. This applies to key AND value of the map.
Zusätzliche Informationen und Funktionen |
- Das Tutorial wurde am 17.04.2014 von MOD angelegt.
- Die aktuellste Version wurde am 31.07.2019 von MOD gespeichert.
|
|