有什么办法可以创建一个带有静态值的数据表?
Column : col1,col2.....coln
Rows : for n number of rows
For first row values row11,row12......row1n
for second row values row21,row22.....row2n
.
.
.
for nth row values rown1,rown2......rownn
使用lambda / linq ...的任何时尚方式...都可以以一种专业方式在一行中..
我知道这是一个很酷的问题(“过时的技术”-John Saunders),但我无法抗拒:
const int cols = 6;
const int rows = 20;
DataTable nt = new DataTable("new table");
nt.Columns
.AddRange(
Enumerable
.Range(1,cols)
.Select(x => new DataColumn("col"+x.ToString())).ToArray());
Enumerable
.Range(1,rows).ToList()
.ForEach(x => nt.Rows
.Add(
Enumerable
.Range(1,cols)
.Select(y => "row"+x.ToString()+"col"+y.ToString()).ToArray()));
对不起奇怪的格式,但我不想使用水平滚动条。
本文收集自互联网,转载请注明来源。
如有侵权,请联系 [email protected] 删除。
我来说两句