How to define multidimensional arrays of different types in powershell -


i'm stuck.

i create multidim array following structure

$x[index]['word']="house"   $x[index]['number']=2,5,7,1,9 

where index first dimension 0 to... n

second dimension has 2 fields "word" , "number"

and each of these 2 fields holds array (the first strings, second numbers)

i not know how declare $x

i've tried

$x = @(()),@(@()) - doesn't work 

or

$x= ("word", "number"), @(@()) - doesn't work either 

or

$x = @(@(@(@()))) - nope 

then want use array this:

$x[0]["word"]= "bla bla bla" $x[0]["number]= "12301230123" $x[1]["word"]= "lorem ipsum" $x[2]["number]=... $x[3]... $x[4]... 

the frequent errors

array assignment failed because index '0' out of range.

unable index object of type system.char/int32

i accomplish using arrays[][] or jaws @ no .net [,] stuff.

i think i'm missing something.

if understood correctly, you're looking array of hashtables. can store whatever want inside object-array, store hashtables can search words or numbers keys. ex:

$ht1 = @{} $ht1["myword"] = 2 $ht1["23"] = "myvalue" $ht2 = @{} $ht2["1"] = 12301230123  $arr = @($ht1,$ht2)   ps > $arr[1]["1"] 12301230123  ps > $arr[0]["myword"] 2  ps > $arr[0]["23"] myvalue 

if know how many need, can use shortcut create it:

#create array of 100 elements , initialize hashtables $a = [object[]](1..100) 0..($a.length-1) | % { $a[$_] = @{ 'word' = $null; 'number' = $null } }   #now have array of 100 hastables keys initialized. it's ready recieve values. ps > $a[99]  name                           value ----                           ----- number word 

and if need add pair later, can use:

$a += @{ 'word' = $yourwordvar; 'number' = $yournumbervar } 

Comments

Popular posts from this blog

linux - xterm copying to CLIPBOARD using copy-selection causes automatic updating of CLIPBOARD upon mouse selection -

c++ - qgraphicsview horizontal scrolling always has a vertical delta -