none
Powershell Array List RRS feed

  • Question

  • Doubts in Powershell 2D Array

    Can I able to restrict the 2D Array Growth

    Eg : $arr = New-Object System.Collections.ArrayList

     

    When I use this $Arr in the For Loop and at any point of time it should not hold more than 3 records. But the For loop data might contain more 100 records and in the each increment it should insert and delete the records.

    In this below data :

    Col1 Col2 Col3 $Arr

    100 101 102
    200 201 202
    300 301 302 102,202,302
    400 401 402 202,302,402
    500 501 502 302,402,502
    600 601 602 402,502,602
    700 701 702 502,602,702
    800 801 802 602,702,802
    900 901 902 702,802,902
    1000 1001 1002 802,902,1002
    1100 1101 1102 902,1002,1102

    At the 3 Row, it should have Col3[0][2], Col3[1][2], Col3[2][2] in the Comma Separated Format

    When it moved to 4th Row in the loop iteration then $Arr should Remove $Arr[0][0] and Add Col3[3][2]

    Similarly till last records

    How to arrive this logic using Powershell using ArrayList

    Thanks for any Help

    • Moved by Bill_Stewart Tuesday, November 7, 2017 10:57 PM Unanswerable drive-by question
    Friday, October 6, 2017 8:05 AM

All replies

  • PS D:\scripts> $arr = [string[]]::new(3)
    PS D:\scripts> $arr[0] = "zero"
    PS D:\scripts> $arr[1] = "one"
    PS D:\scripts> $arr[2] = "two"
    PS D:\scripts> $arr[3] = "three"
    Index was outside the bounds of the array.
    At line:1 char:1
    + $arr[3] = "three"

    \_(ツ)_/



    • Edited by jrv Friday, October 6, 2017 8:41 AM
    Friday, October 6, 2017 8:38 AM
  • Maybe you are looking for a wrap around queue.  ArrayLists are expandable by default. 


    \_(ツ)_/

    Friday, October 6, 2017 8:46 AM