PowerShell无法创建System.Collections.ArrayList对象的解决方案
问题
执行以下PowerShell代码创建ArrayList时报错:
[System.Collections.ArrayList]$list= @() #list.Add($MonitorName);
错误提示:
Cannot convert value to type "System.Collections.ArrayList". Only core types are supported in this language mode.
解决方案
在语言约束模式下,可使用PowerShell原生数组实现列表功能,示例代码如下:
$list= @() $list += "aaa" $list += "bbb"
通过原生数组的+=操作符添加元素,无需依赖System.Collections.ArrayList这类非核心类型,可适配当前语言模式的限制。
内容的提问来源于stack exchange,提问作者Sravani
相关产品推荐
相关产品推荐

