开发者

Prevent ArrayList.Add() from returning the index

is there a way to supress the return value (=Index) of an ArrayList in Powershell (usin开发者_如何转开发g System.Collections.ArrayList) or should I use another class?

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


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

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

Another option is to redirect to $null:

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


Two more options :)

Pipe to out-null

$myArrayList.Add("test") | Out-Null  

Assign the result to $null:

$null = $myArrayList.Add("test")
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜