1

So in C# you can define an array like so:

string[] Demo;
string[,] Demo;
string[,,] Demo;

What does the , represent?

LJNielsenDk
  • 1,414
  • 1
  • 16
  • 32
Bauer
  • 21
  • 5
  • 1
    possible duplicate of [What are the differences between a multidimensional array and an array of arrays in C#?](http://stackoverflow.com/questions/597720/what-are-the-differences-between-a-multidimensional-array-and-an-array-of-arrays) – Jeroen Vannevel Aug 23 '15 at 18:24

3 Answers3

5

The dimensions.

  • No comma: 1 dimension
  • 1 comma: 2 dimensions
  • 2 commas: 3 dimensions
  • and so on...

Learn more about multi-dimensional arrays on MSDN.

Preston Guillot
  • 6,493
  • 3
  • 30
  • 40
Matías Fidemraizer
  • 63,804
  • 18
  • 124
  • 206
3

Multi-dimensional arrays.

The following example would declare a string array with two dimensions:

string[,] demo = new string[5, 3];

The [,] syntax is useful, for example, if you have a method taking a 2D array as a parameter:

void myMethod(string[,] some2Darray) { ... }

Note the difference between multi-dimensional arrays (e.g. string[,]), which are like a matrix:

+-+-+-+-+
| | | | |
+-+-+-+-+
| | | | |
+-+-+-+-+
| | | | |
+-+-+-+-+

and jagged arrays (e.g. string[][]), which are basically arrays of arrays:

+------------+
| +-+-+-+-+  |
| | | | | |  |
| +-+-+-+-+  |
+------------+
| +-+-+-+-+  |
| | | | | |  |
| +-+-+-+-+  |
+------------+
| +-+-+-+    |
| | | | |    |  <- possible in jagged arrays but not in multi-dimensional arrays
| +-+-+-+    |
+------------+

Reference:

Heinzi
  • 167,459
  • 57
  • 363
  • 519
0

These are multi-dimensional arrays.

The difference between this and array[][] as you might be used to is described here and here

Community
  • 1
  • 1
James Webster
  • 31,873
  • 11
  • 70
  • 114