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")
精彩评论