Typical beginner question
Ok, the second call:
LogArr(Array(1,2,3))
implies Array As Object, so the two arrays are exactly the same type, but Params() As Object should accept an array of any type.
In fact the routine would work even if called passing an array of strings:
B4X:
Sub AppStart (Form1 As Form, Args() As String)
Dim arr(10) As Int
For i = 0 To 9
arr(i) = i
Next
' Why the first call is wrong and the second one not?
LogArr(arr) ' <--- ERROR
LogArr(Array(1,2,3))
End Sub
B4X:
Private Sub LogArr(Params() As Object)
For i = 0 To Params.Length - 1
Log(i & TAB & Params(i))
Next
End Sub
Ok, the second call:
LogArr(Array(1,2,3))
implies Array As Object, so the two arrays are exactly the same type, but Params() As Object should accept an array of any type.
In fact the routine would work even if called passing an array of strings:
B4X:
Sub AppStart (Form1 As Form, Args() As String)
Dim arr(10) As String
For i = 0 To 9
arr(i) = "a " & i
Next
LogArr(arr) ' <--- works
End Sub
Last edited: