Let’s say I create a jagged 2d array like so:
public static char[,] phoneLetterMapping = { {'0'}, {'1'}, {'A', 'B', 'C'} };
Now, given the first index of the array, I would like to determine the length of the inner array.
I would like to be able to do something like:
phoneLetterMapping[2].length
I can do that in Java. But the Intellisense menu doesn’t return the normal members of an array when I type in the first bracket of the [][] 2d array.
How do I get the inner array lengths of my 2d array in C#?
The declaration you posted won’t even compile in C#, which is your main issue.
You’ve declared, using
char[,]a 2D, non-jagged array, but you’re trying to instantiate a jagged array on the right side of the “=” by using{ {'0'}, {'1'}, {'A', 'B', 'C'} }.Now, if you declare it differently:
Then you can simply call something like:
The line of code you posted at first, however, won’t compile in C#.