Usually when a new object is added to an array, you are most concerned about its performance problems, based on experience. The first example below will tell you the wrong way to do this:
Copy Code code as follows:
Measure-command {
$ar = @ ()
for ($x =0; $x-lt 10000; $x + +)
{
$ar + + $x
}
}
In this loop, the array adds a number of new objects through the symbol "+ +". This will take a long time, because when you change the size of the PowerShell you need to create a new array each time.
Here's a very quick way to-arraylist, which can better handle variable arrays:
Copy Code code as follows:
Measure-command {
$ar = New-object-typename System.Collections.ArrayList
for ($x =0; $x-lt 10000; $x + +)
{
$ar. ADD ($x)
}
}
Two pieces of code for the same thing, the second method will be more efficient.
Experience:
Originally used so long PS found himself has been using the method is not the best, it seems to be the PS play fine, in the final analysis you have to see. NET Master.