我试图使用powershell脚本从arraylist中找到元素的索引,但是得到以下给定的错误
方法调用失败,因为[System.String []]不包含 方法名为'IndexOf'。
使用的代码:
[String[]]$eventList = New-Object System.Collections.ArrayList
$eventList.GetType().FullName
$index = $eventList.IndexOf('cvv');
答案 0 :(得分:1)
您正在将ArrayList强制转换为数组,只需删除强制转换:
$eventList = New-Object System.Collections.ArrayList
此外,您可能需要考虑使用List< string>而不是ArrayList:
$eventList = New-Object System.Collections.Generic.List[string]