0

Using Powershell, I would like to declare array of array.

Basically, if I write this code:

$array1 = ("AA", "BB")

$array2 = ("CC", "DD"),("EE", "FF")

$array1[0][0] + $array1[0][1]
$array2[0][0] + $array2[0][1]
$array2[1][0] + $array2[1][1]

I expect to get :

AABB
CCDD
EEFF

But the actual output is

AA
CCDD
EEFF

This is due because of the first array is detected as a simple string array, and not an array of array of string.

Is there any way to "force" $array1 to be an array of one array ?

I tried:

$array1 = [string[][]]("AA", "BB")

$array1 = (("AA", "BB"))

$array1 = @()
$array1+=(@("AA","BB"))

$array1 = [array]::CreateInstance([array],1)
$array1[0] = @("AA","BB")
$array1[0][0] + $array1[0][1]

but none of these works

1 Answer 1

2

Try in this way:

$array1 = ,("AA", "BB")

the comma is the 'array operator' in powershell.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.