I am trying to pass an array to functions and fill it, and then print the results outside of the functions.
But the first function doesn't recognize the array list object I am passing to it.
Main file:
. $funcFile
$myParam = "Hello World"
$myObj = getMyObject $myParam
$myObj.myArrayList.Count # This works (outputs 0)
myFunction2 ($myObj.myArrayList)
$myObj.myArrayList.Count # This also works (outputs 0)
fncFile:
function getMyObject([String] $myParam) {
$myObj = @{
"myArrayList" = (New-Object System.Collections.ArrayList)
}
return $myObj
}
function myFunction2 ([System.Collections.ArrayList] $myArr){
$myArr.Count # This doesn't work (outputs nothing)
if($myArr -eq $null) {
Write-Host "Array List Param is null" # This condition is FALSE - nothing is printed
}
}
What am I doing wrong?
How can I use the same ArrayList in function2 and other inner functions?