这是一个示例,您可以尝试按照我没有使用 String[] 执行此操作,但您可以得到这个想法
//
// 1. Create two dimensional array
//
const int dim = 1000;
double[,] array = new double[dim,dim];
Random ran = new Random();
for(int r = 0; r < dim; r++)
{
for(int c = 0; c < dim; c++)
{
array[r,c] = (ran.Next(dim)); // fill it with random numbers.
}
}
// 2. Create ArrayDataView class in which
// constructor you pass the array
// and assign it to DataSource property of DataGrid.
dataGrid1.DataSource = new ArrayDataView(array);
对于 String[][] 这里是一个例子
string[][] arr = new string[2][];
arr[0] = new String[] {"a","b"};
arr[1] = new String[] {"c","d"};
DataGrid1.DataSource = arr[0];
DataGrid1.DataBind();//The result is: a,b in datagrid
使用 LinQ 看看这个
List<string> names = new List<string>(new string[]
{
"John",
"Frank",
"Bob"
});
var bindableNames =
from name in names
select new {Names=name};
dataGridView1.DataSource = bindableNames.ToList();
将 LINQ 用于多密度阵列
string[][] stringRepresentation = ds.Tables[0].Rows
.OfType<DataRow>()
.Select(r => ds.Tables[0].Columns
.OfType<DataColumn>()
.Select(c => r[c.ColumnName].ToString())
.ToArray())
.ToArray();