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.

0

1 Answer 1

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 
Sign up to request clarification or add additional context in comments.

1 Comment

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.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.