还是数组的问题
我现在有个数组,array1={1-5,1-3,1-4,1-1,1-2,5-5,5-3,5-4,5-1,5-2,4-5,4-3,4-4,4-1,4-2,3-5,3-3,3-4,3-1,3-2,2-5,2-3,2-4,2-1,2-2}
如何根据现有数组内的元素,让其自动生成一个5行5列的表。
1-11-21-31-41-5
2-12-22-32-42-5
3-13-23-33-43-5
。
。
。
其实这个表有多少行,多少列不确定,要看这个数组有多少元素的。请前辈们帮忙忙啊。在线等
[解决办法]
var array=new string[]{"1-5","1-3","1-4","1-1","1-2","5-5","5-3","5-4","5-1","5-2","4-5","4-3","4-4","4-1","4-2","3-5","3-3","3-4","3-1","3-2","2-5","2-3","2-4","2-1","2-2"}; var result=array.GroupBy(s=>Regex.Match(s,"\\d+(?=-)").Value).OrderBy(g=>int.Parse(g.Key)); DataTable dt=new DataTable(); result.Select(g=>g.Key).ToList().ForEach(k=>dt.Columns.Add("clumns"+k)); result.ToList().ForEach(r=>dt.Rows.Add(r.ToArray()));
[解决办法]