The idea is that I have a sorting mechanism that sorts according to the red value (later I wanna build on so I can sort by green and blue value too). I am having trouble implementing this sorting mechanism.
I have a class called Colorbox which is basically a List<Color> but this way I can put a List<Color> in a List<Colorbox>.
What my mean goal is that I can order this Colorbox according to 1 color (red, blue, green) value. (e.g. so that most left value in the list has least red).
I tried implementing a toCompare override (don't know if this works in C# but I know in Java the compare too is called upon when you call sort() method).
This gives me a code like following:
public int CompareTo(object obj) {
Color toCompare = (Color) obj;
if (this.CompareTo(toCompare) == 1)
{
return 1;
}
else
{
return 0;
}
}
but I don't see how I can implement my sort by color there or sort in general. Do I have to write an extra sort() to override the original.
I don't really have an idea what this sort code should do. Does it order value by value until it can go over the list and nothing is changed? or is this a way too long approach for this idea?
Underneath I give the general code of the class:
internal class Colorbox
{
private List<Color> box = new List<Color>();
int colorPicker = 0;
public Colorbox(List<Color> colorList)
{
this.box = colorList;
}
}
I hope someone can help explain what I should do or in which direction I should look to solve this problem.
Thanks a lot already and ask anything if I haven't been clear.
