0

I get this error:

assignment to [2,1] failed because assignment to slices is not supported. At C:\Lab7A.ps1:7 char:9 + $data[$x,$y] = read-host "day $y" + ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ + CategoryInfo : InvalidOperation: (:) [], RuntimeException + FullyQualifiedErrorId : ArraySliceAssignmentFailed

I've tried using an input variable for the read-host lines and then assigning the variable to the correct index but get the same error.

I've tried searching Google for different combinations of "assignment to slices not supported" with no luck.

    $data = @()

    for($x = -0; $x -lt 3; $x++){
    $data[$x,0] = read-host "name: "
    for($y = 1; $y -lt 6; $y++){
        $data[$x,$y] = read-host "day $y"
    }
}

I want to cycle through a 2D array and have a list 3 names with 5 entries each for the number of steps they did in a day.

Ranadip Dutta
  • 8,857
  • 3
  • 29
  • 45
  • 7
    Possible duplicate of [Powershell Multidimensional Arrays](https://stackoverflow.com/questions/9397137/powershell-multidimensional-arrays) (apply `$data = New-Object 'string[,]' 3,5`). – JosefZ May 28 '19 at 23:52
  • try doing a search in the SO search bar for `powershell multidimensional array` ... [*grin*] – Lee_Dailey May 29 '19 at 00:29

0 Answers0