我对linq语法不是很熟悉,并且我不确定此查询是否与我要实现的查询完全匹配,但其运行正常。我如何才能使其变得更好,并且有可能避免使用新的元组或新的对象?
byte[] ShuffledBytes= new byte[20];
byte[] Indecies = new byte[20]; //holds the right index for each byte in Bytes
var orderdBytes =
Indecies.
Zip(ShuffledBytes, (i, b) => new Tuple<byte,byte>(b,i)).
OrderBy(o => o.Item2).
Select(o => o.Item1).
ToArray();
我想您想要的Array.Sort
不是LINQ。重载之一将一个数组用作键,将另一个作为排序项:
Array.Sort(Indecies, ShuffledBytes);
不需要额外的对象ShuffledBytes会根据Indecies中的值进行排序。
另一种选择是使用排序字典或键值对的列表,而不是2个数组。
本文收集自互联网,转载请注明来源。
如有侵权,请联系 [email protected] 删除。
我来说两句