Array.Sort for DataRow array  
Author Message
HuberSepp





PostPosted: Visual C# Language, Array.Sort for DataRow array Top

Hi,

I want to sort a DataRow array with my own compare function. How can I do that

Can I call Array.Sort(datarows, myowncomparefunction) like that

How does myowncomparefunction have to look like

I hope, that's a simple question for the experts.



Visual C#12  
 
 
Paul Louth





PostPosted: Visual C# Language, Array.Sort for DataRow array Top

Write a comparer first:

class DataRowComparer : IComparer<DataRow>
{
    public int Compare(DataRow x, DataRow y)
    {
        // return -1 for less than
        // return 0 for equal
        // return +1 for greater than
    }
}

Then create one and pass it your array sort:

   DataRowComparer comparer = new DataRowComparer();
   Array.Sort<DataRow>(rows, comparer);