Adagio
Well-known member
- Joined
- Dec 12, 2005
- Messages
- 162
- Programming Experience
- Beginner
Hi, having a bit of a sorting problem here, hoping some kind sould can help me with it
Situation: I have a class with three properties:
A (integer), B (string), C (integer)
I have added a list of these items in random sequence to a list:
A B C
3 Bacon 1
1 Doom 3
2 Even 2
1 Abe 1
2 Zebra 1
1 True 2
At first it has to group them together on property A:
1 Doom 3
1 Abe 1
1 True 2
2 Even 2
2 Zebra 1
3 Bacon 1
The next part is sorting on property C, still keep them in a group:
1 Abe 1
1 True 2
1 Doom 3
2 Zebra 1
2 Even 2
3 Bacon 1
The last part is sorting on property B for groups. In the above situation group 1 is using "Abe" for sorting, group 2 is using "Zebra" and group 3 is using "Bacon". This way group 3 should be after group 1, but before group 2:
1 Abe 1
1 True 2
1 Doom 3
3 Bacon 1
2 Zebra 1
2 Even 2
Would it be possible to sort like this?
In my class I have Implemented IComparable, but I can't seem to figure out what I would need to write in CompareTo. Or do I need to take another aproach to sorting this list?
Situation: I have a class with three properties:
A (integer), B (string), C (integer)
I have added a list of these items in random sequence to a list:
A B C
3 Bacon 1
1 Doom 3
2 Even 2
1 Abe 1
2 Zebra 1
1 True 2
At first it has to group them together on property A:
1 Doom 3
1 Abe 1
1 True 2
2 Even 2
2 Zebra 1
3 Bacon 1
The next part is sorting on property C, still keep them in a group:
1 Abe 1
1 True 2
1 Doom 3
2 Zebra 1
2 Even 2
3 Bacon 1
The last part is sorting on property B for groups. In the above situation group 1 is using "Abe" for sorting, group 2 is using "Zebra" and group 3 is using "Bacon". This way group 3 should be after group 1, but before group 2:
1 Abe 1
1 True 2
1 Doom 3
3 Bacon 1
2 Zebra 1
2 Even 2
Would it be possible to sort like this?
In my class I have Implemented IComparable, but I can't seem to figure out what I would need to write in CompareTo. Or do I need to take another aproach to sorting this list?