how do i declare const array?

  • Thread starter Thread starter George Ter-Saakov
  • Start date Start date
G

George Ter-Saakov

I need to declare const 2 dimensional array

something like
string[][2] topmenu = { {"menu1", "aaa"}, {"menu2", "bbb"} }

Thanks.
George.
 
string[][] topmenu = {new string[] {"menu1", "aaa"},new string[]{"menu2",
"bbb"}};
 
George,

Hope following code helps you.....

// Single-dimensional arrays.
int[] myArray1 = new int [5];
string[] myArray2 = new string[6];

// Multidimensional arrays.
int[,] myArray3 = new int[4,2];
int[,,] myArray4 = new int [4,2,3];

// Jagged array.
int[][] myArray5 = new int[3][];

Thanks,

Tap
 
None of it works with const.

const string[,] siblings = { {"Gus", "Amy"}, {"Mary", "Albert"} }; - error

Array initializers can only be used in a variable or field initializer. Try
using a new expression instead.


George.

MS News (MS ILM) said:
string[][] topmenu = {new string[] {"menu1", "aaa"},new string[]{"menu2",
"bbb"}};

string[,] siblings = { {"Gus", "Amy"}, {"Mary", "Albert"} };

string[,] siblings2 = new string[,] { {"Gus","Amy"}, {"Mary","Albert"} };

George Ter-Saakov said:
I need to declare const 2 dimensional array

something like
string[][2] topmenu = { {"menu1", "aaa"}, {"menu2", "bbb"} }

Thanks.
George.
 
Back
Top