< Back

New-ArrayList

Fri Jan 10, 2020 8:54 pm

NAME New-ArrayList



SYNOPSIS

Create a new array to append objects into.





SYNTAX

New-ArrayList [[-Type] <String>] [-Legacy] [<CommonParameters>]





DESCRIPTION

By default, constructs an empty [System.Collections.Generic.List<System.Object>] collection.



When specifying -Type, constructs an empty [System.Collections.Generic.List<T>] collection.



-Legacy parameter will override -Type, providing a [System.Collections.ArrayList] instead.



Capture New-ArrayList in a variable to reuse it with Add-ArrayObject.





PARAMETERS

-Type <String>

Optionally specify the only object type that the new list will accept.

This will construct a "type-safe" Generic.List collection.

-Type expects a string ("int") instead of a type notation ([int]).



Required? false

Position? 1

Default value

Accept pipeline input? false

Accept wildcard characters? false



-Legacy [<SwitchParameter>]

Outputs a [System.Collections.ArrayList] collection, ignoring the -Type parameter.



Required? false

Position? named

Default value False

Accept pipeline input? false

Accept wildcard characters? false



<CommonParameters>

This cmdlet supports the common parameters: Verbose, Debug,

ErrorAction, ErrorVariable, WarningAction, WarningVariable,

OutBuffer, PipelineVariable, and OutVariable. For more information, see

about_CommonParameters (https:/go.microsoft.com/fwlink/?LinkID=113216).



INPUTS



OUTPUTS

[System.Collections.Generic.List<System.Object>]

[System.Collections.Generic.List<T>]

[System.Collections.ArrayList]





NOTES





https://stackoverflow.com/questions/230 ... in-c-sharp

https://serverfault.com/questions/70883 ... rn-as-arra

ylist

https://connect.microsoft.com/PowerShel ... ls/1622532



-------------------------- EXAMPLE 1 --------------------------



PS C:\\>$a = New-ArrayList



Create $a as an empty Generic.List, to use later with Add-ArrayObject.









-------------------------- EXAMPLE 2 --------------------------



PS C:\\>$a = New-ArrayList -Type string



Create $a as an empty Generic.List collection. This list is "type-safe,"

meaning it will append only objects of type [string], rejecting others.









-------------------------- EXAMPLE 3 --------------------------



PS C:\\>$a = New-ArrayList -Legacy



Create $a as an empty ArrayList. Generic.List is recommended, but ArrayList

remains for anyone insistent...especially because of the module name.











RELATED LINKS

https://github.com/brianbunke/ArrayList