我有一个多维数组,我想将它写入 .csv,当它在 Excel 中显示时,我希望它具有相同的矩阵式顺序。
string[,] output = new string[,] { {"n=", "128", "256", "512", "1024", "2048", "4096", "8192", "16384", "32768", "65536", "131072", "262144", "524288", "1048576", "2097152", "4194304", "8388608"},
{ "Selection", timeSelection128, timeSelection256, timeSelection512, timeSelection1024, timeSelection2048, timeSelection4096, timeSelection8192, timeSelection16384, timeSelection32768, timeSelection65536, timeSelection131072, timeSelection262144, timeSelection524288, timeSelection1048576, timeSelection2097152, timeSelection4194304, timeSelection8388608 },
{ "Insertion", timeInsertion128, timeInsertion256, timeInsertion512, timeInsertion1024, timeInsertion2048, timeInsertion4096, timeInsertion8192, timeInsertion16384, timeInsertion32768, timeInsertion65536, timeInsertion131072, timeInsertion262144, timeInsertion524288, timeInsertion1048576, timeInsertion2097152, timeInsertion4194304, timeInsertion8388608 },
{ "Merge", timeMerge128, timeMerge256, timeMerge512, timeMerge1024, timeMerge2048, timeMerge4096, timeMerge8192, timeMerge16384, timeMerge32768, timeMerge65536, timeMerge131072, timeMerge262144, timeMerge524288, timeMerge1048576, timeMerge2097152, timeMerge4194304, timeMerge8388608 },
{ "Quick", timeQuick128, timeQuick256, timeQuick512, timeQuick1024, timeQuick2048, timeQuick4096, timeQuick8192, timeQuick16384, timeQuick32768, timeQuick65536, timeQuick131072, timeQuick262144, timeQuick524288, timeQuick1048576, timeQuick2097152, timeQuick4194304, timeQuick8388608 } };`
那是我的多维数组,现在我正在做这样的事情...... [5x18]
StringBuilder sb = new StringBuilder();
for (int x = 0; x < 5; x++)
{
for (int y = 0; y < 18; y++)
{
sb.AppendLine(string.Join(delimiter, output[x,y]));
}
File.AppendAllText(filePath, sb.ToString());
}
但这只是给了我一个excel文件,第一列中的所有内容一个接一个。我需要数组中的每一行都是 Excel 中的一行,等等。