Dim makemap As Map
makemap.Initialize
For i = 0 To 5
makemap.Put($"${i}"$,$"A-${i}"$)
'makemap.Put(i,$"A-${i}"$)
Next
Log(makemap)
Log(makemap.GetKeyAt(2))
Log(makemap.GetValueAt(2))
Log(makemap.Get(2))
Log("******************")
In the first case the type of the key is a string and so does not match an int in the get. "2" vs 2. In some cases there maybe implicit type conversion.
In the second case, the key is an int and matches the int in the get, 2 vs 2.
In the first case the type of the key is a string and so does not match an int in the get. "2" vs 2. In some cases there maybe implicit type conversion.
In the second case, the key is an int and matches the int in the get, 2 vs 2.
Yes is so.
If is type String it does not cast.
Only in this way work
B4X:
Dim makemap As Map
makemap.Initialize
For i = 0 To 5
'makemap.Put($"${i}"$,$"A-${i}"$)
makemap.Put(i,$"A-${i}"$)
Next
Log(makemap)
Log(makemap.GetKeyAt(2))
Log(makemap.GetValueAt(2))
Log(makemap.Get(2))
For Each Key As Int In makemap.Keys '<---- AS INT
Dim value As String = makemap.Get(Key)
Log($"Key: ${Key} Value:${value}"$)
Next
Dim makemap As Map
makemap.Initialize
For i = 0 To 5
makemap.Put($"${i}"$,$"A-${i}"$)
'makemap.Put(i,$"A-${i}"$)
Next
Log(makemap)
Log(makemap.GetKeyAt(2))
Log(makemap.GetValueAt(2))
Log(makemap.Get(2))
For Each Key As String In makemap.Keys '<---- AS STRING
Dim value As String = makemap.Get(Key)
Log($"Key: ${Key} Value:${value}"$)
Next
I think the first one map is
"0" = "A-0"
"1" = "A-1"
...
Notice that the " " are not shown but the key and value are strings
So you have to Log(Log(makemap.Get("2")) <-- 2 as string
In second map is
0 = "A-0"
1 = "A-1"
...
So you have to log(makemap.Get(2)) <-- 2 as int
I think the first one map is
"0" = "A-0"
"1" = "A-1"
...
Notice that the " " are not shown but the key and value are strings
So you have to Log(Log(makemap.Get("2")) <-- 2 as string
In second map is
0 = "A-0"
1 = "A-1"
...
So you have to log(makemap.Get(2)) <-- 2 as int
For Each Key In makemap.Keys '<---- OBJECT
Dim value As String = makemap.Get(Key)
Log($"Key: ${Key} Value:${value}"$)
Next
Case Sensitive:
B4X:
Dim makemap As Map
makemap.Initialize
For i = 0 To 5
' makemap.Put($"${i}"$,$"A-${i}"$)
makemap.Put(i,$"A-${i}"$)
Next
Log(makemap)
Dim i As Int = 2
Log(makemap.GetKeyAt(i))
Log(makemap.GetValueAt(i))
OK. Ultimately if you treat them as an object everything works. Thinking about it, it is also right that this is the case, given that you can enter any type of data in a map.
B4X:
Dim makemap As Map
makemap.Initialize
For i = 0 To 5
makemap.Put($"${i}"$,$"A-${i}"$)
'makemap.Put(i,$"A-${i}"$)
Next
For Each Key In makemap.Keys
Dim value As String = makemap.Get(Key)
Log($"Key: ${Key} Value:${value}"$)
Next