how to join 2 dimensional array of string in c#?
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.
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];
}
}
for (int i=0;i<27;i++)
for (int j=0;j<27;j++)
c[i,j] = a [i,j] + b[i,j];
精彩评论