Carlos, it's really quite simple. All you need is a class implementing
IComparer. For example:
public class ArrayComparer : IComparer
{
// IComparer implementation
public int Compare(object obj1, object obj2)
{
int result;
double[] m_Temp1 = obj1 as double[];
double[] m_Temp2 = obj2 as double[];
if (m_Temp1 != null && m_Temp2 != null)
{
if (m_Temp1[2] < m_Temp2[2])
result = -1;
else if (m_Temp1[2] > m_Temp2[2])
result = 1;
else
result = 0;
return result;
}
else
{
throw new ArgumentException("Objects are not arrays of
doubles!");
}
}
}
Then you can simply use the following to sort your array:
IComparer myComparer = new ArrayComparer();
Array.Sort(mData, myComparer);
Of course, you should add some error checking to make sure the arrays have
the expected structure (and do in fact contain three elements).
--
Kai Brinkmann [MSFT]
Please do not send e-mail directly to this alias. This alias is for
newsgroup purposes only.
This posting is provided "AS IS" with no warranties, and confers no rights.
"Carlos" <cp@swa.com> wrote in message
news:%2****************@tk2msftngp13.phx.gbl...
Do you have any sample code or site where I can check it ?
Thanks
"Jon Skeet [C# MVP]" <sk***@pobox.com> wrote in message
news:MP************************@msnews.microsoft.c om... Carlos <cp@swa.com> wrote: Ok I have the following Jagged array
<snip>
Now I need to sort the array using the third column or element of the
second
array keeoing the values that belong to that element same, like when you
have three columns in excel and select to sort by column C so all values
rearrange. Any idea How can I do that.
Yes - use Array.Sort, passing in an instance of a class which
implements IComparer. That class's Compare method would cast both its
parameters to a double[], and compare the third elements of those
arrays.
--
Jon Skeet - <sk***@pobox.com>
http://www.pobox.com/~skeet Blog: http://www.msmvps.com/jon.skeet
If replying to the group, please do not mail me too