The following
syntax
can be used to
return an array of Single values
.
The
array
is a
reference type
. Hence, even though
xx
is a local variable within the function when it is returned from the function it gives
reference to the array object
on the heap holding the values assigned within the function.
xx---refers--->array on heap
. The statement
Dim arrayOfElements = GetArrayOfElements(6)
makes the local variable
arrayOfElements---refers--->array on heap
, so as it is required in the question, the
array
is returned, with the
elements assigned within the function
.
Sub Main
Dim arrayOfElements = GetArrayOfElements(6)
For each element as Single in arrayOfElements
Console.WriteLine(element)
Next element
End Sub
Private Function GetArrayOfElements(ByVal Abc as integer) as Single()
Dim xx(Abc) as Single
For I as integer = 1 to Abc
xx(I) = I * 2
Next I
Return xx
End Function
If the function is required to be used
from outside the class
in which it is declared, then
public
or other appropriate access level shall be for
Function GetArrayOfElements