how do i declare const array?

G

George Ter-Saakov

I need to declare const 2 dimensional array

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

Thanks.
George.
 
M

MS News \(MS ILM\)

string[][] topmenu = {new string[] {"menu1", "aaa"},new string[]{"menu2",
"bbb"}};
 
M

MS News \(MS ILM\)

string[,] siblings = new string[2, 2] { {"Mike","Amy"}, {"Mary","Albert"} };
 
T

Tap

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
 
G

George Ter-Saakov

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.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,769
Messages
2,569,582
Members
45,057
Latest member
KetoBeezACVGummies

Latest Threads

Top