直接上代码,麻烦指教,谢谢,急!!!!!! List<string[]> listRow = new List<string[]>();
 string[] tempRow = new string[19];
foreach (DataRow dr in dt.Rows)
                    {
                        for (int j = 0; j < 18; j++)
                        {
                            tempRow[j] = dr[j + 1].ToString().Trim();
                        }
//这里出现问题,里面的每个元素内容始终是最新加入的元素内容
                        listRow.Add(tempRow);
                        //清空tempRow
                        int n = 0;
                        foreach (string tempStr in tempRow)
                        {
                            tempRow[n++] = null;
                        }
                    }

解决方案 »

  1.   

    List<string[]> listRow = new List<string[]>();
     string[] tempRow = new string[19];
    foreach (DataRow dr in dt.Rows)
                        {
    //这里重新new下或者empRow = new string[19];放在里面                        for (int j = 0; j < 18; j++)
                            {
                                tempRow[j] = dr[j + 1].ToString().Trim();
                            }
    //这里出现问题,里面的每个元素内容始终是最新加入的元素内容
                            listRow.Add(tempRow);
                            //清空tempRow
                            int n = 0;
                            foreach (string tempStr in tempRow)
                            {
                                tempRow[n++] = null;
                            }
                        }
      

  2.   

    把string[] tempRow = new string[19]; 放在foreach中试试.
      

  3.   

    把string[] tempRow = new string[19];放进第一个循环内,必须每次循环new一次,否则listRow中所有元素都是同一个数组,内容自然一样,
      

  4.   

     foreach (string tempStr in tempRow)
                            {
                                tempRow[n++] = null;  改成tempStr=""或者null
                            }
    这里错了