Prevent ArrayList.Add() from returning the index Prevent ArrayList.Add() from returning the index powershell powershell

Prevent ArrayList.Add() from returning the index


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")