我知道这是一个愚蠢的问题,但有没有人有一个优雅的(或非优雅的)LINQ方法将2D数组(object [,])转换为一维数组(object []),包括第一个维度2D阵列?
例:
// I'd like to have the following array
object[,] dim2 = {{1,1},{2,2},{3,3}};
// converted into this kind of an array... :)
object[] dim1 = { 1, 2, 3 };
Run Code Online (Sandbox Code Playgroud)
您声称自己想要a 1D array (object[]) comprised of the first dimension of the 2D array,所以我假设您正在尝试选择原始2D阵列的子集.
int[,] foo = new int[2, 3]
{
{1,2,3},
{4,5,6}
};
int[] first = Enumerable.Range(0, foo.GetLength(0))
.Select(i => foo[i, 0])
.ToArray();
// first == {1, 4}
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
1890 次 |
| 最近记录: |