Is there any built-in C# support for doing an index sort?
More Details:
I have several sets of data stored in individual generic Lists of double.
These ar
The following code achievs an indexed sort. Note the ToArray() call to clone the data array. If omited, the data array becomes sorted, too.
static void Main(String[] args)
{
Int32[] data = new Int32[] { -6, 6, 5, 4, 1, 2, 3, 0, -1, -2, -3, -4, -5 };
Int32[] indices = Enumerable.Range(0, data.Length).ToArray();
Array.Sort(data.ToArray(), indices);
foreach (Int32 index in indices)
{
Console.Write(String.Format("{0} ", data[index]));
}
Console.ReadLine();
}
The output is as exspected.
-6 -5 -4 -3 -2 -1 0 1 2 3 4 5 6