Arrays, as opposed to collections like Arraylists, are fixed size. See here:
It’s a little less straight forward to inspect the members of an Array object because if you just pipe your array to Get-Member you get information about the objects from within the array.
Notice that “IsFixedSize” property? Try calling that.
If you check the Microsoft page on the System.Array you’ll see they also remark that these Arrays are fixed size and that the classes in the System.Collections namespaces can be resized.
thx for the answer ,for what i know if an array was create from foreach-object ,i will be the fixed size array.
And to insert value you should first turn it into none fixed size
At that point you could use the += syntax of adding to an array BUT you lose the ability to choose the index.
In your last example it’s likely tearing down the array and rebuilding it into an arraylist, so a similar performance hit to the += method, but if you’re only doing it occasionally not a big deal.
What I would wonder about is if there’s any performance benefit to just using the Add method in your loop against the collection instead of capturing the output in an variable, resulting in a fixed sized array.
mycoordinate to the another placeA is directed
and placeA to the place B is undirected
so i figure i could first get all the posible path like
A -B
B-A
and i add the my coordinate into the first index so it look like
O-A-B
O-B-A
This way if “Coordinate” was nothing, you can just leave it as $null, but later if you wanted to add value to it you’d just call the variable containing your object, reference the property, and set it. $MyObject.Coordinate = "47,-122" or whatever it should be.
If that doesn’t work for your use case then I would definitely stick with something from the Collections namespace like an Arraylist. But think about objects, or maybe a hashtable could help here too if you’ve got a unique key for everything.