Converting Arrays

How would I convert Array-of-arrays:

byte[ ][ ] scores;

Into a Multidimensional array:

string[ , ] names;
LVL 29
leonstrykerAsked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
leonstrykerAuthor Commented:
This my code:

        public string[,] querycols1010(int queryID)
        {
            string[][] tempval;
            string [,] colInfo;

            tempval =  comLink.querycols1010(queryID);

            for (int k = 0; k <= 5; k++)
            {
                for (int i = 0; i <= tempval.GetUpperBound(0); i++)
                {
                    colInfo[k,i] = tempval[k][i];
                }
            }
            return colInfo;
        }

Open in new window


I am getting this error: unassigned local variable 'colInfo'
0
Julian HansenCommented:
You have not assigned an array to this

string [,] colInfo;

Should be

string [,] colInfo = new string[5, tempval.GetUpperBound(0)];

Put the above just before the for loop and after the tempval assignment.
0
Bootstrap 4: Exploring New Features

Learn how to use and navigate the new features included in Bootstrap 4, the most popular HTML, CSS, and JavaScript framework for developing responsive, mobile-first websites.

leonstrykerAuthor Commented:
Ok, changed it as you specified and that cleared the error

      public string[,] querycols1010(int queryID)
        {
            string[][] tempval;
            //string [,] colInfo;

            tempval =  comLink.querycols1010(queryID);

            string[,] colInfo = new string[5, tempval.GetUpperBound(0)];

            for (int k = 0; k <= 5; k++)
            {
                for (int i = 0; i <= tempval.GetUpperBound(0); i++)
                {
                    colInfo[k,i] = tempval[k][i];
                }
            }
            return colInfo;
        }

Open in new window


Then I run it, I get a different error "Index was outside the bounds of the array". Should I be running it from 1 to 6 instead of 0 to 5?
0
leonstrykerAuthor Commented:
Thanks for your help. i will ask a debugging question separately.
0
Julian HansenCommented:
Just interested to know why you used my suggestion and then awarded points to a different expert.

In answer to the question - yes the index should be 6 I thought the loop ran to <5 not <=5 so the index needs to be 6.
0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
C#

From novice to tech pro — start learning today.