正确声明列表集合?
Properly Declare a List Collection?
在 Powershell V4 中,如何正确声明 List<>
集合?
我试着这样声明它
$listCollection = New-Object 'System.Collections.Generic.List<string>'
它没有用,给我错误。
在 Powershell 中,您需要在指定列表项的类型时使用方括号 [...]
:
PS > $listCollection = New-Object System.Collections.Generic.List[string]
PS > $listCollection.GetType()
IsPublic IsSerial Name BaseType
-------- -------- ---- --------
True True List`1 System.Object
PS >
请注意,这与使用尖括号 <...>
.
的 C# 不同
在 Powershell V4 中,如何正确声明 List<>
集合?
我试着这样声明它
$listCollection = New-Object 'System.Collections.Generic.List<string>'
它没有用,给我错误。
在 Powershell 中,您需要在指定列表项的类型时使用方括号 [...]
:
PS > $listCollection = New-Object System.Collections.Generic.List[string]
PS > $listCollection.GetType()
IsPublic IsSerial Name BaseType
-------- -------- ---- --------
True True List`1 System.Object
PS >
请注意,这与使用尖括号 <...>
.