So I'm starting with PowerShell and this is odd to me. I put a breakpoint in the last line and when I run the script $newArray is "abc" then it pauses in Write-Output and I stop the debugger. If I run it again, $newArray is "abcabc" and so on. For one, I think I'm doing something wrong as this behavior is so weird to me, like it stores in memory despite of stopping the debugger. And secondly I would expect $newArray to be an array and not a single string with the values concatenated. Any clues?
$array = "a", "b", "c";
$newArray;
foreach ($item in $array )
{
$newArray += $item
}
Write-Output "Just before ending script";
$newArray = @(). about_arrays$NewArrayto be blank. [grin] thus it will always accumulate until you clear what is in memory.$NewArrayto be any specific type. so, when you add a string to the blank $Var, it becomes a STRING var. then, when you add another thing that can be coerced to a string ... it gets added to the existing string. [grin] ///// the fix is to force the new $Var to be an array. the simplest is to declare it as such, thus ...[array]$NewArray = @().