# Odd behavior in Multidimensional Arrays

**URL:** <https://forums.powershell.org/t/odd-behavior-in-multidimensional-arrays/15465>\
**Category:** PowerShell Help\
**Created:** [January 8, 2021, 11:19pm UTC](https://forums.powershell.org/t/odd-behavior-in-multidimensional-arrays/15465 "2021-01-08T23:19:09Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![mitchvh](https://avatars.discourse-cdn.com/v4/letter/m/5f9b8f/32.png) [@mitchvh](https://forums.powershell.org/u/mitchvh)\
**Post date:** [January 8, 2021, 11:19pm UTC](https://forums.powershell.org/t/odd-behavior-in-multidimensional-arrays/15465/1 "2021-01-08T23:19:09Z")

</div>

**UPDATE:**

Nevermind. All I need to do is enclose them each in Parentheses. There went WAY too much time for something so simple. (Shame I don’t know how to delete this thread)

**Original:**

So, I have written a class with a 2 dimensional array member. It also has a member Method that combines two of these Grid classes. Here’s the weird bit – Powershell errors out when trying to reference the multidimensional array in the [Grid] class that is passed into the function.

```
class Grid {
   [system.management.automation.host.bufferCell[,]] $Cells
   ...
   [void] CombineGrid([Grid] $G) {
      ...
   }
   ...
}
```

Here’s the bit where the problem occurs:

```
[void] CombineGrid ([Grid] $G){
   ...
   $This.Cells[$y,$x] = $This.NewGridCell($G.cells[$y,$x].character, ...
   # ^ ^
   # No error at this point, Referencing |
   # $This.cells Here it complains about a missing
   # ']', as though it's a regular array.
   ...
}
```

Can anyone explain this to me? or how to get around the problem? I’m not sure how this could be. It’s not being compressed into Uni-dimensional array, since if I try to index into it as a normal array, I get the error “You cannot index into a 2 dimensional array with index [0].”

What am I missing?

---

<div class="post-metadata">

**Author:** ![dotnVo](https://avatars.discourse-cdn.com/v4/letter/d/4af34b/32.png) [@dotnVo](https://forums.powershell.org/u/dotnVo)\
**Post date:** [May 16, 2024, 8:28pm UTC](https://forums.powershell.org/t/odd-behavior-in-multidimensional-arrays/15465/2 "2024-05-16T20:28:02Z")

</div>

Closed on May 16, 2024, 8:28pm UTC


