防止 ArrayList.Add() 返回索引 [英] Prevent ArrayList.Add() from returning the index

查看:21
本文介绍了防止 ArrayList.Add() 返回索引的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

有没有办法抑制 ArrayList 的返回值(=Index)在 Powershell 中(使用 System.Collections.ArrayList)还是我应该使用另一个班级?

is there a way to supress the return value (=Index) of an ArrayList in Powershell (using System.Collections.ArrayList) or should I use another class?

$myArrayList = New-Object System.Collections.ArrayList($null)
$myArrayList.Add("test")
Output: 0

推荐答案

您可以强制转换为 void 以忽略 Add 方法的返回值:

You can cast to void to ignore the return value from the Add method:

[void]$myArrayList.Add("test") 

另一种选择是重定向到 $null:

Another option is to redirect to $null:

$myArrayList.Add("test") > $null

这篇关于防止 ArrayList.Add() 返回索引的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆