Good day to all,
In this thread Erel explaining how to assign Arrays in List Items.
In the first code writes
It is something like this and i understand why this is happens.
I don't understand the next code where he declares the same array inside for loop
Why the previous arrays is not lost? If i log(Arr(0)) after for loop what are we gonna see?
In this thread Erel explaining how to assign Arrays in List Items.
In the first code writes
B4X:
Dim arr(3) As Int
Dim List1 As List
List1.Initialize
For i = 1 To 5
arr(0) = i * 2
arr(1) = i * 2
arr(2) = i * 2
List1.Add(arr) 'Add the whole array as a single item
Next
arr = List1.Get(0) 'get the first item from the list
Log(arr(0)) 'What will be printed here???
It is something like this and i understand why this is happens.
I don't understand the next code where he declares the same array inside for loop
B4X:
Dim arr(3) As Int 'This call is redundant in this case.
Dim List1 As List
List1.Initialize
For i = 1 To 5
Dim arr(3) As Int
arr(0) = i * 2
arr(1) = i * 2
arr(2) = i * 2
List1.Add(arr) 'Add the whole array as a single item
Next
arr = List1.Get(0) 'get the first item from the list
Log(arr(0)) 'Will print 2
Why the previous arrays is not lost? If i log(Arr(0)) after for loop what are we gonna see?
Attachments
Last edited: