Adding elements to an array

A single item can be added to the end of an array using the assignment by addition operator:

$myArray = @() 
$myArray += "New value" 

The preceding command is equivalent to the following:

$myArray = $myArray + "New value" 

In the background, PowerShell creates a new array with one extra element, copies the existing array in, and then adds the value for the new element before disposing of the original array. The larger the array, the less efficient this operation becomes.

The same technique can be used to join one array to another, demonstrated as follows:

$firstArray = 1, 2, 3 
$secondArray = 4, 5, 6 
$mergedArray = $firstArray + $secondArray 
..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset
3.17.74.227