How to declare natural ordering by implementing the generic IComparer interface in C# .NET
March 21, 2017 1 Comment
In this post we showed how to declare natural ordering for a custom type by implementing the generic IComparable interface. We saw that it required us to implement the CompareTo method. The example we looked at was a simple Triangle class where we said that triangles can be ordered based on their areas. That’s probably a reasonable comparison for triangle.
However, what about the following object?
public class Building
{
public double Area { get; set; }
public int NumberOfRooms { get; set; }
public string Address { get; set; }
public bool ForSale { get; set; }
public DateTime DateBuilt { get; set; }
}