Sorting two dimensional array how to ?

C

Carlos

I have the following two dimension array:

public double[,] mData = new double[259200,3];

now I need to sort the values based on the values of third index of the
second dimension, like

[0,0]= 11
[0,2]= 22
[0,3]= 444


[1,0]=1
[1,2]=33
[1,3]=11


[2,0]=333
[2,2]=44
[2,3]= 222

I need it to be after sorting using the third (index 2) of the second
dimension

[0,0]= 1
[0,2]= 33
[0,3]= 11


[1,0]=333
[1,2]=44
[1,3]=222


[2,0]=11
[2,2]=22
[2,3]= 444

Thanks in advance for you help
 
J

Jon Skeet [C# MVP]

Carlos said:
I have the following two dimension array:

public double[,] mData = new double[259200,3];

now I need to sort the values based on the values of third index of the
second dimension, like

The way to do this is to use jagged arrays instead of rectangular ones.
Then you've got an array of arrays, and you can sort that in the same
way that you can sort any other single-dimensional array with
Array.Sort, providing an IComparer to compare elements (each element
will be an array, that you take the 3rd element of to use for
comparisons).
 
C

Carlos

Thanks Jon
I check the jagged array
Jon Skeet said:
Carlos said:
I have the following two dimension array:

public double[,] mData = new double[259200,3];

now I need to sort the values based on the values of third index of the
second dimension, like

The way to do this is to use jagged arrays instead of rectangular ones.
Then you've got an array of arrays, and you can sort that in the same
way that you can sort any other single-dimensional array with
Array.Sort, providing an IComparer to compare elements (each element
will be an array, that you take the 3rd element of to use for
comparisons).
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top