title: How to compare two numeric values (SByte, Double) stored as Objects in .NET 2.0?
body: <p>In my custom sorting algorithm, I need to compare numeric types stored as Objects in an array. We can have SByte, Double, Int32, etc values mixed in one array. How can I compare two values of that array in my IComparer implementation?</p>
  
  <hr>
  
  <p>An example. Let's say we have two numeric values:</p>
  
  <pre class="lang-cs prettyprint-override"><code>object var1 = (sbyte)-8;
  object var2 = (double)123.456;
  </code></pre>
  
  <p>It would be nice if code like the following one worked, but it fails:</p>
  
  <pre><code>IComparable cmp1 = var1 as IComparable;
  IComparable cmp2 = var2 as IComparable;
  MessageBox.Show(cmp1.CompareTo(cmp2).ToString());
  </code></pre>
  
  <p>How can I compare two boxed numeric values in .NET 2.0?</p>