Search code examples
vb.netlistoverridingcomparablerectangles

How can I compare a list of RectangleF?


I would like to sort a List(Of RectangleF) somehow.

It is going to be huge, so I would rather not have to create a separate class that implements Comparable -

Is it possible to somehow override the RectangleF itself, to add a Comparable, and ovverride a CompareTo to compare by X ?

I am using VB.NET, but I would appreciate C# advice as well.


Solution

  • You can use LINQ's OrderBy methods to sort however you choose.

    For example, if you want to order the list by X, you could do:

    Dim orderedByX = theList.OrderBy(Function(rect) rect.X)