mirror of
https://github.com/adambard/learnxinyminutes-docs.git
synced 2024-12-24 10:01:38 +00:00
Adjusting array section to be more accurate
The default array object is mutable, but is of a fixed length. Changing comments to better reflect that.
This commit is contained in:
parent
f67ae9b311
commit
5c79b4288c
@ -183,11 +183,12 @@ $someVariable # => 5
|
|||||||
# Ternary Operators exist in Powershell 7 and up
|
# Ternary Operators exist in Powershell 7 and up
|
||||||
0 ? 'yes' : 'no' # => no
|
0 ? 'yes' : 'no' # => no
|
||||||
|
|
||||||
# The default array object in Powershell is an immutable array
|
# The default array object in Powershell is an fixed length array
|
||||||
$defaultArray = "thing","thing2","thing3"
|
$defaultArray = "thing","thing2","thing3"
|
||||||
# you are unable to add or remove objects
|
# you can add objects with '+=', but cannot remove objects
|
||||||
$defaultArray.Add("thing4") # => Exception "Collection was of a fixed size."
|
$defaultArray.Add("thing4") # => Exception "Collection was of a fixed size."
|
||||||
# To have a mutable array, you will need to use the .NET ArrayList class
|
# To have a more workable array, you'll want the .NET [ArrayList] class
|
||||||
|
# It is also worth noting that ArrayLists are significantly faster
|
||||||
|
|
||||||
# ArrayLists store sequences
|
# ArrayLists store sequences
|
||||||
[System.Collections.ArrayList]$array = @()
|
[System.Collections.ArrayList]$array = @()
|
||||||
|
Loading…
Reference in New Issue
Block a user