0

I've had a look at both ASP.Net c# adding items to jagged array and vb.net assign array to jagged array but I just can't seem to work this out...

So, essentially, it's this. I have a function that builds a list of values from a query or two. I'm adding each value returned to a list then converting the list to an array. All is good

However, I now need to return two values, so a multi dimension array appears more suitable. Essentially, this is what I want to do:

        string[][] array2D = new string[2][];
        array2D[0] = new string[3] { "one", "two", "three" };
        array2D[1] = new string[3] { "abc", "def", "ghi" };

All good so far. However, I don't know the values that I want to plug in to the array at the time of array initialisation, so, this is what I'd expect to be able to do:

        string[][] array2D = new string[2][];
        //array2D[0] = new string[3] { "one", "two", "three" };
        //array2D[1] = new string[3] { "abc", "def", "ghi" };

        string[] deviceIDS = { "one", "two", "three" };
        string[] groupIDS = { "abc", "def", "ghi" };

        array2D[0] = new string[deviceIDS.Length] deviceIDS;
        array2D[1] = new string[deviceIDS.Length] groupIDS;

But it really doesn't like the last two lines, report it needs a ;

2
  • 2
    array2D[0] = deviceIDS; array2D[1] = groupIDS;? Commented Mar 6, 2017 at 10:53
  • remove the variable names at the end of the last two lines. Commented Mar 6, 2017 at 10:54

1 Answer 1

2

You have already created arrays here:

string[] deviceIDS = { "one", "two", "three" };
string[] groupIDS = { "abc", "def", "ghi" };

So you only need to set references to these arrays:

array2D[0] = deviceIDS;
array2D[1] = groupIDS;
Sign up to request clarification or add additional context in comments.

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.