gpt4 book ai didi

powershell - Powershell Arraylist RemoveAt不起作用

转载 作者:行者123 更新时间:2023-12-03 00:31:43 24 4
gpt4 key购买 nike

我正在使用Powershell Arraylist来保存通过拆分字符串生成的列表。当我尝试使用以下代码删除列表中的第一项时,enitre列表将为空。

[System.Collections.ArrayList]$teststringlist=New-Object System.Collections.ArrayList
$teststring ="Test1,Test2,Test3"
$teststringlist = $teststring.Split(",")
$teststringlist=$teststringlist.RemoveAt(0)
我如何在PowerShell中删除Arraylist的索引0处的第一项

最佳答案

RemoveAt不返回值(请参见https://docs.microsoft.com/en-us/dotnet/api/system.collections.arraylist.removeat?view=netcore-3.1),因此它不是

$teststringlist=$teststringlist.RemoveAt(0)
只是这样做:
$teststringlist.RemoveAt(0)

关于powershell - Powershell Arraylist RemoveAt不起作用,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/63354447/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com