2

Can these 2 arrays talk to each other or do they need to be the same type i.e [,] can only talk to other [,] arrays.

Or if I had:

char [,] 2darray =new char [2,2];

Could it pass it's values to a method that had a 2d array like:

Shirts(char [][] sizes)

This is pseudo code used for example only im really just interested in knowing what the differences in this type of array call are if any and if they can talk to each other or not.

Spooler
  • 222
  • 1
  • 10

1 Answers1

4

These two types are different. They have different representation in memory, so they are not interchangeable.

A 2D array char m[,] is required to have rows of identical size, and all rows must be present. In contrast, an array of arrays char m[][] is allowed to have rows of variable length, or even some missing rows.

An element of an array of arrays is an array, which you can pass around as a separate entity. A 2D array is a single unit; its indexer operator needs an index for each dimension. In other words, you can do this

char m[][] ...
char r[] = m[2]; // Allowed

but you cannot do this

char m[,] ...
char r[] = m[2]; // Does not compile
Sergey Kalinichenko
  • 714,442
  • 84
  • 1,110
  • 1,523
  • 1
    So one of these is a 2D array and one is an array of arrays ? Could you go into a little bit more detail please, I think i understand what you're saying but i'm not entirely sure. – Spooler Jul 09 '16 at 11:45