简体   繁体   中英

2d char array to string

I want to use a 2d char array and have more than one string:

    char[,] str = new char[9,1000];
    int i=0;
    while (i < 9)
            {
                last[i] = str[i].ToString();
                i++;
            }

but this doesn't work.

您正在初始化变量i = 9,因此while循环条件将永远不会运行

string []last = new string[9];
for( int i=0; i<9; ++i )
{
  char []chars = new char[1000];
  for( int j=0; j<1000; j++ )
    chars[j] = str[i,j];
  last[i] = new string(chars);
}

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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