Prevent ArrayList.Add() from returning the index

.net, arraylist, powershell

Solution

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

Problem

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 ```

Original source

Related problems