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

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

问题描述

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

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

预先感谢
米尔德

thanks in advance Milde

推荐答案

可以将其强制转换为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天全站免登陆