Reputation:
In Powershell V4, how would I properly declare a List<>
collection?
I tried declaring it like this
$listCollection = New-Object 'System.Collections.Generic.List<string>'
It didn't work and gave me errors.
Upvotes: 1
Views: 3003
Reputation:
In Powershell, you need to use square brackets [...]
when specifying the type of the list's items:
PS > $listCollection = New-Object System.Collections.Generic.List[string]
PS > $listCollection.GetType()
IsPublic IsSerial Name BaseType
-------- -------- ---- --------
True True List`1 System.Object
PS >
Note that this is different from C#, which would use angle brackets <...>
.
Upvotes: 2