2

I have a multi dimensional array but i want to be able to instantiate and initialize it in one line does anyone know how to do this?

Here is what i have at the moment.

int[,] Columns = [3,2];
Columns[0,0]= 1;
Columns[1,0]= 0;
Columns[2,0]= 2;
Columns[0,1]= "Distinct";
Columns[1,1]= "Sum";
Columns[2,1]= "Distinct";

im trying to get somthing along the lines of:

enter image description here

If anyone could help it would be much appreciated.

2
  • Why does it suddenly turn in to a string array at line 5? And also, could you illustrate what your'e hoping to achieve somehow? Commented Sep 17, 2016 at 8:15
  • object[,] Columns = { { 1, "Distinct" }, { 0, "Sum" }, { 2, "Distinct" } }; Commented Sep 17, 2016 at 8:31

1 Answer 1

2

You can, you can use something called a collection initializer with rectangular arrays! But you can't declare the array type as int and try and store strings (such as "Sum") in it too.

You could use the object type to store different data types in the same collection:

object[,] Columns = { { 1, 0, 2 }, { "Distinct", "Sum", "Distinct" } };
Sign up to request clarification or add additional context in comments.

1 Comment

This is exactly what i was looking for. Thanks :)

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.