title: Overriding CompareTo when there are multiple ways to compare two objects of the same type?
body: <p>What's a sound approach to override the <code>CompareTo()</code> method in a custom class with multiple approaches to comparing the data contained in the class?  I'm attempting to implement <code>IComparable(Of T)</code> just so I have a few of the baseline interfaces implemented.  Not planning on doing any sorting yet, but this will save me down the road if I need to.</p>
  
  <p>Reading MSDN states mostly that we have to return 0 if the objects are equal, -1 if obj1 is less than obj2, or 1 is obj1 is greater than obj2.  But that's rather simplistic.</p>
  
  <p>Consider an IPv4 address (which is what I'm implementing in my class).  There's two main numbers to consider -- the IP address itself, and the CIDR.  An IPv4 address by itself is assumed to have a CIDR of /32, so in that case, in a <code>CompareTo</code> method, I can just compare the addresses directly to determine if one is greater or less than the other.  But when the CIDR's are different, then things get tricky.</p>
  
  <p>Assume obj1 is <code>10.0.0.0/8</code> and obj2 is <code>192.168.75.0/24</code>.  I could compare these two addresses a number of ways.  I could just ignore the CIDR, and still regard as obj2 as being greater than obj1.  I could compare them based on their CIDR, which would be comparing the size of the network (and a /8 will trump a /24 quite easily).  I could compare them on both their numerical address AND their CIDR, on the off chance obj2 was actually an address <em>inside</em> the network defined by obj1.</p>
  
  <p>What's the kind of approach used to handle situations like this?  Can I define two <code>CompareTo</code> methods, overloaded, such that one would evaluate one address relative to another address, and the second would evaluate the size of the overall network?  How would the .NET framework be told which one to use depending on how one might want to sort an array?  Or do some other function that relies on <code>CompareTo()</code>?</p>