I would like to sort a list base on two values. Is it possible to add another compare in my class BlkFleche ?
I need the list to be sort base on the X and then base on the Y, those are from coordinates.
So if I have my X and Y like that :
[10,1]
[4,6]
[9,2]
[10,4]
[4,2]
[10,6]
I would like the end result to be :
[4,2]
[4,6]
[9,2]
[10,1]
[10,4]
[10,6]
I'm using a list because I need to keep data in relation with the coordinates.
public class blkFleche : IComparable<blkFleche>
{
public double positionX { get; set; }
public double positionY { get; set; }
public string attNOCABLE { get; set; }
public string attNOFIBRE { get; set; }
public int CompareTo(blkFleche other)
{
return this.positionX.CompareTo(other.positionX);
}
}
private void btnRead()
{
List
<blkFleche
> listBlkSort
= new List
<blkFleche
>(); //...
blkFleche blkNew
= new blkFleche
(); //...
blkNew.positionX = blkRef.Position.X;
blkNew.positionY = blkRef.Position.Y;
//...
listBlkSort.Add(blkNew);
//...
listBlkSort.Sort();
}