473,385 Members | 1,919 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,385 software developers and data experts.

IComparable and multiple sorting

Hello,
i dot not manage to write the code to sort a array on multiple columns.
ArrayList people = new ArrayList();
people.Add(new Person("John", "Doe", 76));
people.Add(new Person("Matt", "Dire", 80));
people.Add(new Person("Matew", "Vinz", 75));
people.Add(new Person("Arlett", "Blaste", 84));

so, i want now sorting by Name, Surname and Year :

Array.Sort(people,Person.sortNameSurnameYearAscend ing());// Méthode devant
retourner l'objet IComparer pour l'aide de tri.
public static IComparer sortNameSurnameYearAscending()
{
return (IComparer) new sortNameSurnameYearAscendingHelper();
}private class sortNameSurnameYearAscendingHelper : IComparer
{

int IComparer.Compare(object a, object b)
{ Person a1 = (Person)a; Person b1 = (Person)b;
?? what do here...
//return 1;
}

}
Oct 17 '06 #1
1 3987
Check my blog here:

http://sholliday.spaces.live.com/blog/

6/19/2006
Advanced IComparer // Sorting on Multiple Values

"Steph" <pi**@pipo.comwrote in message
news:45***********************@news.orange.fr...
Hello,
i dot not manage to write the code to sort a array on multiple columns.
ArrayList people = new ArrayList();
people.Add(new Person("John", "Doe", 76));
people.Add(new Person("Matt", "Dire", 80));
people.Add(new Person("Matew", "Vinz", 75));
people.Add(new Person("Arlett", "Blaste", 84));

so, i want now sorting by Name, Surname and Year :

Array.Sort(people,Person.sortNameSurnameYearAscend ing());// Méthode devant
retourner l'objet IComparer pour l'aide de tri.
public static IComparer sortNameSurnameYearAscending()
{
return (IComparer) new sortNameSurnameYearAscendingHelper();
}private class sortNameSurnameYearAscendingHelper : IComparer
{

int IComparer.Compare(object a, object b)
{ Person a1 = (Person)a; Person b1 = (Person)b;
?? what do here...
//return 1;
}

}


Oct 17 '06 #2

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

3
by: Cybertof | last post by:
Hello, Could someone please explain me the difference between the 2 interfaces IComparable and IComparer ? In which cases use one or the other ? Are they dedicated to own classes or built-in...
1
by: raffelm | last post by:
In the first class below, I get an error that AnotherClientBaseDataRecord does not implement IComparable.CompareTo(object)...yet the second class below is implemented identicially and it does get...
2
by: ESPNSTI | last post by:
Hi, I'm trying to use a generics dictionary with a key class that implements and needs IComparable<>. However when I attempt to use the dictionary, it doesn't appear to use the IComparable<> to...
2
by: Stefan L | last post by:
Hi everybody, when migrating to the .NET 2.0 framework we decided to encourage the use of generic functions because they ought to run faster than their equivalent object-implemantations. Now...
1
by: Brett Romero | last post by:
What are the reasons to use one over the other? SortedList implements IComparer.Compare(). Why would you also want to create a SortedList class that implements IComparable.CompareTo()? I know...
2
by: Jim | last post by:
Creating a datagridView with a dataReader. Why do I get this message when I click on the column header (some, but not all the column headers) to sort?? sqlDR = sqlCMD.ExecuteReader Dim intCol...
2
by: John Devlon | last post by:
Hi, Could somebody please tell me how to use Icomparable in a .NET project? Like I was a 5 year old? I'm trying to sort an array of objects and I can't get it to work .... How do I modify the...
8
by: SimeonArgus | last post by:
I need to sort a list of points, so I've considered using an IComparable implementation. Should be easy, right? But I need to know two things in the CompareTo function, not one. Test1: I need to...
5
by: John Devlon | last post by:
Hi everyone, With this post I would like to ask you all a small question. I'm trying to sort an array of objects using IComparable. Adding below displayed code to a class and triggering the...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.