Make Types Sortable
Because you often don’t know how your type will be used, making the
objects sortable is highly recommended whenever possible.
In the Vector3d class example, in order to make the objects comparable, we’ll add an
_id field and implement the IComparable<Vertex3d> interface.
The _id field will be what determines the order (it doesn’t make much sense to sort on
The sorting function is simple. It takes an object of Vertex3d and returns one of three
< 0 this is less than other
0 this is same as other
> 0 this is greater than other
Within the CompareTo function, you can do anything you want to arrive at those
values. In our case, we can do the comparison ourself or just call the same function on
the _id field.
|All times are GMT +5.5. The time now is 11:16.|