sooon
sooon

Reputation: 4878

Declare multi dimensional array

I have this array that I need it to be convert from JS to C#:

var allwinning = new Array(
        ["000", "001", "002"],
        ["000", "010", "020"],
        ["000", "011", "022"],
        ["000", "100", "200"],
        ["000", "101", "202"],
        ["000", "110", "220"],
        ["001", "002", "003"],
        ["001", "011", "021"])

The array has to be this way because at one point of the game I will have to compare and match element by element to see if you match the combo to decide if you win.

Should I convert it to List<string> or to ArrayList?

Upvotes: 1

Views: 9946

Answers (1)

user2530227
user2530227

Reputation:

// Two-dimensional array.

int[,] array2D = new int[,] { { 1, 2 }, { 3, 4 }, { 5, 6 }, { 7, 8 } };

// The same array with dimensions specified.

int[,] array2Da = new int[4, 2] { { 1, 2 }, { 3, 4 }, { 5, 6 }, { 7, 8 } };

// A similar array with string elements.

string[,] array2Db = new string[3, 2] { { "one", "two" }, { "three", "four" },
                                    { "five", "six" } };

// Three-dimensional array.

int[, ,] array3D = new int[,,] { { { 1, 2, 3 }, { 4, 5, 6 } }, 
                              { { 7, 8, 9 }, { 10, 11, 12 } } };

// The same array with dimensions specified.

int[, ,] array3Da = new int[2, 2, 3] { { { 1, 2, 3 }, { 4, 5, 6 } }, 
                                   { { 7, 8, 9 }, { 10, 11, 12 } } };

Upvotes: 8

Related Questions