1

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

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

What does the , represent?

1

3 Answers 3

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.

Sign up to request clarification or add additional context in comments.

Comments

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:

Comments

0

These are multi-dimensional arrays.

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

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.