我有这个:
string[] old = new string[] {"a","b","c","d"};
表示二维数组列的值:
double[,] values = new double[,] {{1,2,3,4},{5,6,7,8},{1,3,5,9}};
如何使用 linq 重新编码此二维数组的列,将字符串数组值重新排序为
string[] newer = new string[] {"c","a","d","b"};
我正在使用辅助 int 数组来保留新索引,但我想使用 LINQ!:)
int[] aux = new int[old.Length];
for (int i = 0; i < newer.Length; i++)
{
for (int j = 0; j < old.Length; j++)
{
if (old[j] == newer[i])
{
aux[i] = j;
}
}
}
double[,] newvalues = new double[values.GetLength(0), values.GetLength(1)];
for (int i = 0; i < values.GetLength(0); i++)
{
for (int j = 0; j < values.GetLength(1); j++)
{
newvalues[i, j] = values[i, aux[j]];
}
}
values = newvalues;