有没有办法抑制 ArrayList 的返回值(=Index) 在 Powershell 中(使用 System.Collections.ArrayList)或者我应该使用 又一堂课?
$myArrayList = New-Object System.Collections.ArrayList($null)
$myArrayList.Add("test")
Output: 0
您可以强制转换为 void 以忽略 Add 方法的返回值:
[void]$myArrayList.Add("test")
另一个选项是重定向到 $null:
$myArrayList.Add("test") > $null
还有两个选择:)
管道到 out-null
$myArrayList.Add("test") | Out-Null
将结果赋给$null:
$null = $myArrayList.Add("test")
我花了一段时间才找到解决方案。人工智能并没有太大帮助。老谷歌在这里提供帮助和指导