日期:2014-05-18 浏览次数:21103 次
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()));
------解决方案--------------------