开发者

how to join 2 dimensional array of string in c#?

开发者 https://www.devze.com 2023-02-11 06:57 出处:网络
i have problem: string[,] a 开发者_运维问答= string[27,27]; a = bootsrapMinor(data); string[,] b = string[27,27];

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];
0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号