日期:2014-05-18 浏览次数:21039 次
var dtbl = new DataTable(); for (int i = 0; i < 4; i++) { dtbl.Columns.Add(i.ToString()); } dtbl.Rows.Add("11", "12", "13", "01"); dtbl.Rows.Add("21", "22", "23", "01"); dtbl.Rows.Add("31", "32", "33", "01"); dtbl.Rows.Add("41", "42", "43", "02"); dtbl.Rows.Add("51", "52", "53", "02"); var row = 3; var column = 3; var lines = dtbl.Select(); var rarr = new string[lines.Length * column]; int rem = lines.Length % row; int mr = lines.Length - rem; for (int i = 0; i < lines.Length; i++) { var arr = lines[i].ItemArray; var r = i < mr ? row : rem; for (int j = 0; j < column; j++) { rarr[i / row * row * column + j * r + i % row] = arr[j].ToString(); } } var result = string.Join(",", rarr); // 11,21,31,12,22,32,13,23,33,41,51,42,52,43,53