Hi there,
I need to sort multi-dimensional array by two columns. I.e. I have the following:
a b c
-----------
1 12 1
0 10 2
1 10 3
1 15 4
0 14 5
So the result should look like this:
a b c
-----------
1 15 4
1 12 1
1 10 3
0 14 5
0 10 2
As you can see I need to order it in descending order by column A first and then by column B so that column C should still be mapped appropriately.
When I had just 2 columns (B and C) it was pretty easy to do:
Hashtable HTPreferenceOrd er = new Hashtable();
//next line is in loop
HTPreferenceOrd er.Add(B,C);
//end loop
int count= HTPreferenceOrd er .Count;
int[] B= new int[count];
int[] C= new int[count];
HTPreferenceOrd er.Keys.CopyTo( B,0);
HTPreferenceOrd er.Values.CopyT o(C, 0);
Array.Sort(B, C);
Array.Reverse(C );
That's it. I got column C in descending order like i wanted it to be. But now i had to add column A and sort by it first. Please help, need to do it ASAP.
Thanks in advance.
I need to sort multi-dimensional array by two columns. I.e. I have the following:
a b c
-----------
1 12 1
0 10 2
1 10 3
1 15 4
0 14 5
So the result should look like this:
a b c
-----------
1 15 4
1 12 1
1 10 3
0 14 5
0 10 2
As you can see I need to order it in descending order by column A first and then by column B so that column C should still be mapped appropriately.
When I had just 2 columns (B and C) it was pretty easy to do:
Hashtable HTPreferenceOrd er = new Hashtable();
//next line is in loop
HTPreferenceOrd er.Add(B,C);
//end loop
int count= HTPreferenceOrd er .Count;
int[] B= new int[count];
int[] C= new int[count];
HTPreferenceOrd er.Keys.CopyTo( B,0);
HTPreferenceOrd er.Values.CopyT o(C, 0);
Array.Sort(B, C);
Array.Reverse(C );
That's it. I got column C in descending order like i wanted it to be. But now i had to add column A and sort by it first. Please help, need to do it ASAP.
Thanks in advance.
Comment