1

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?

Alexei Levenkov
  • 98,904
  • 14
  • 127
  • 179
sooon
  • 4,718
  • 8
  • 63
  • 116
  • 2
    There is no sensible reason to choose `ArrayList` over `List` unless it is an absolute requirement. Go with the generic version. – Jeroen Vannevel Jan 25 '14 at 01:36
  • @JeroenVannevel Can you elaborate more? I am rather new in C# and it is very different from JS and even OBJ-C. – sooon Jan 25 '14 at 01:39
  • You can find a lot of information [here](http://stackoverflow.com/questions/2309694/arraylist-vs-list-in-c-sharp). – Jeroen Vannevel Jan 25 '14 at 02:15
  • Note that title talks about multidimensional *array*, but post asks about using simple `List` - please check what you actually want. – Alexei Levenkov Jan 25 '14 at 02:19

1 Answers1

8

// 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 } } };
  • +1. As it shows "arrays" as asked in title, but may not what OP needs due to "should I use `List`" in the post... – Alexei Levenkov Jan 25 '14 at 02:20
  • 1
    @Lightwalker this seems like what I want. Let me verify it first and feedback to your answer later. – sooon Jan 25 '14 at 03:03
  • @Lightwalker What is the different of `int[,]` and `int[][]`? – sooon Jan 28 '14 at 00:18
  • 1
    @sooon i don't want to induce you to an error since i can't find nothing explaining this on google. For example string[,] array2Db = new string[3, 2] the "[,]" is indicating it only has one separator(two dimensional array "[,]", meaning two columns). so if you increase to "new string[3, 2, 1]" you would need two separators "[,,]" (three dimensional array "[,,]", meaning three columns). –  Jan 30 '14 at 04:26