简体   繁体   English

如何在C#中加入字符串的二维数组?

[英]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[ , ]' " 错误消息是“运算符'+'无法应用于类型'string [ ]'和'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: 您需要两个嵌套的for循环:

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

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM