【发布时间】:2011-12-06 00:48:22
【问题描述】:
如何使用 Linq 从锯齿状数组中获取列的元素作为平面数组????
public class Matrix<T>
{
private readonly T[][] _matrix;
public Matrix(int rows, int cols)
{
_matrix = new T[rows][];
for (int r = 0; r < rows; r++)
{
_matrix[r] = new T[cols];
}
}
public T this[int x, int y]
{
get { return _matrix[x][y]; }
set { _matrix[x][y] = value; }
}
// Given a column number return the elements
public IEnumerable<T> this[int x]
{
get
{
}
}
}
Matrix<double> matrix = new Matrix<double>(6,2);
matrix[0, 0] = 0;
matrix[0, 1] = 0;
matrix[1, 0] = 16.0;
matrix[1, 1] = 4.0;
matrix[2, 0] = 1.0;
matrix[2, 1] = 6.0;
matrix[3, 0] = 5.0;
matrix[3, 1] = 7.0;
matrix[4, 0] = 1.3;
matrix[4, 1] = 1.0;
matrix[5, 0] = 1.5;
matrix[5, 1] = 4.5;
【问题讨论】:
-
Mmh...您能否提供输入数据和所需输出的示例?
-
声明你想要展平的数组
-
对不起,我一定忘记了...
标签: c# linq jagged-arrays