这件事一直困扰着我,几周前我想出了一个解决办法,但我忘了:
$l=[System.Collections.Generic.List[string[]]]::new()
$l.Add("one", "two", "three")
$l.ToString() #returns ---> System.String[]
"$l" #returns ---> System.String[]
[string]$l #returns ---> System.String[]
$l -join "`n" #returns ---> System.String[]
我期望类似以下内容或由$ofs
变量指定的其他内容:
one
two
three
我在 pwsh 7.4
下面的代码,得到结果,但我在7.5:
撇开调用
$l.Add("one", "two", "three")
无法工作不谈,我假设您的意图是创建一个元素为字符串([string]
)而不是字符串数组[string[]]
( )的列表。因此,将: 更改
$l=[System.Collections.Generic.List[string[]]]::new()
为:
$l=[System.Collections.Generic.List[string]::new()
综上所述:
请注意,
"$l"
和确实尊重偏好变量[string] $l
的值(如果已定义);如果没有后者,则使用单个空格。$OFS