I've got some problems with two-dimensional arrays in PowerShell. Here's what I want to do:
I create a function that is supposed to return a two-dimensional array. When invoking the function I want the return value to be a new two-dimensional array.
For a better understanding I've added an example function, below:
function fillArray() {
$array = New-Object 'object[,]' 2,3
$array[0,0] = 1
$array[0,1] = 2
$array[0,2] = 3
$array[1,0] = 4
$array[1,1] = 5
$array[1,2] = 6
return $array
}
$erg_array = New-Object 'object[,]' 2,3
$erg_array = fillArray
$erg_array[0,1] # result is 1 2
$erg_array[0,2] # result is 1 3
$erg_array[1,0] # result is 2 1
The results are not what I expect. I want to return the information in the same way as declared in the function. So I would expect $erg_array[0,1] to give me 2 instead of the 1,2 I receive with the code above. How can I achieve this?
$erg_array[0,1] # result is 1 2? It should be$erg_array[0,1] # result 2, just as you defined, this is one item, not 2. So that it is not quite clear what you want to get. You are trying to get something not existing.