1

i have problem:

string[,] a = string[27,27];
a = bootsrapMinor(data);
string[,] b = string[27,27];
b = bootstrapMayor(data);

string[,] c = a + b;

the error message is "Operator '+' cannot be applied to operands of type 'string[,]' and 'string[,]' "

anyone have solutions for my problem in joining 2 dimensional array if string? thanks alot.

2
  • Give an example of the final join? Do you want to concatenate strings at the same positions in the arrays? Commented Feb 16, 2011 at 11:01
  • example: a = {"a","b","c","d"}, b = {"e","f","g","h"}, it should e c = {"a","b","c","d","e","f","g","h"} (but it in multidimensional array). thank you Commented Feb 16, 2011 at 11:51

2 Answers 2

1

You can't just "add" two arrays, because the '+' operator is not defined for arrays; you need two nested for loops:

string[,] c = new string[27, 27];
for (int i = 0; i < 27; i++)
{
    for (int j = 0; j < 27; j++)
    {
        c[i, j] = a[i, j] + b[i, j];
    }
}

OK, I misunderstood your question...

This should work:

string[,] c = new string[54, 27];
for (int i = 0; i < 27; i++)
{
    for (int j = 0; j < 27; j++)
    {
        c[i, j] = a[i, j];
        c[27 + i, j] = b[i, j];
    }
}
Sign up to request clarification or add additional context in comments.

3 Comments

hmm, i mean string c = new string [54,27] not string c = new string [27,27]. how to solve this problem? thanks for answering my question :)
I updated my answer. Next time, try to ask your question more clearly ;)
okay :) thank you so much for the answer :) sorry if my question doesn't clear
0
for (int i=0;i<27;i++)
  for (int j=0;j<27;j++)
    c[i,j] = a [i,j] + b[i,j];

2 Comments

hmm, i mean string c = new string [54,27] not string c = new string [27,27]. how to solve this problem? thanks for answering my question :)
ups, then you shuld use a.CopyTo and b.CopyTo but I've never used it. I hope someone else can help you.

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.