Click here to Skip to main content
15,888,351 members
Please Sign up or sign in to vote.
3.00/5 (1 vote)
See more:
Can i declare a 2 dimensional string array like:
C#
string[][] objNames = null;                //String array to store name

objNames = new string[nCount][Messages.DEF_NAMES];   //nCount,Messages.DEF_NAMES are int variables


But getting an error:
Error 1 Invalid rank specifier: expected ',' or ']' <path>\Name.cs 3347  FullNameMultidimensional</path>


why??

Any support will be appreaciated

Thanks in advance

Regardz

Salam
Posted
Updated 20-Sep-11 4:24am
v2

This tutorial[^] might be good reading material.

You are declaring the a jagged array but initiating it incorrectly. The quickest solution is to declare the array as multidimensional.
C#
string [,] objNames = new string[nCount, Messages.DEF_NAMES];
 
Share this answer
 
Comments
E.F. Nijboer 20-Sep-11 10:35am    
The link provided would also be my answer :)
Set the dimensions of the array like this:

C#
objNames = new string[nCount,Messages.DEF_NAMES];
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900