Prevent ArrayList.Add() from returning the index

前端 未结 2 1109
野趣味
野趣味 2020-12-08 06:21

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?

$myArray         


        
相关标签:
2条回答
  • 2020-12-08 07:07

    Two more options :)

    Pipe to out-null

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

    Assign the result to $null:

    $null = $myArrayList.Add("test")
    
    0 讨论(0)
  • 2020-12-08 07:12

    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
    
    0 讨论(0)
提交回复
热议问题