直接上代码,麻烦指教,谢谢,急!!!!!! 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;
}
}
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;
}
}
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;
}
}
{
tempRow[n++] = null; 改成tempStr=""或者null
}
这里错了