ReDim
Definition: Declares dynamic-array variables, and allocates
or reallocates storage space at procedure level.
In general there’s no need for a ReDimstatement in Windows PowerShell; arrays can be resized without having to explicitly call ReDim(and without having to explicitly preserve the existing contents of the array). For example, suppose the following 5 items are assigned to the array $a:
$a = 1 ,2,3,4,5
Want to add a new value – 100 – to the array? This is all you have to do:
$a = $a + 100
If you echo back the value of $ a you’ll get the following:
1
Likewise you can
truncate an array without explicitly
redimensioninganything. Suppose you
want only the first three values in $a. This code assigns just
those first three values (using the syntax
0..2, which means start with item 0 in the array, end with
item 2, and take all the values in between) and assigns them to
$a:
$a = $
a[0..2]
What do you get back
when you execute this command? This is what you get back:
2
3
4
5
100