title: compare different number-types (int, float, double, ...) in .NET
body: <p>I have a function which takes two parameters and returns true if they are equal or false if they are not:</p>
  
  <pre><code>private bool isequal(object a, object b)
  {
      if (a != null)
          return a.Equals(b);
      if (b != null)
          return b.Equals(a);
      //if (a == null &amp;&amp; b == null)
          return true;
  }
  </code></pre>
  
  <p>Now I want to extend this function. It should also return true if a and b are 2 equal numbers but of different type.</p>
  
  <p>For example:</p>
  
  <pre><code>int a = 15;
  double b = 15;
  if (isequal(a,b)) //should be true; right now it's false
  { //...
  }
  </code></pre>
  
  <p>I already found a similar question (with answer) <a href="https://stackoverflow.com/questions/1650091/c-whats-the-best-way-to-compare-double-and-int">best way to compare double and int</a> but a and b could be any type of number or something else than numbers. How can I check if it a and b are numeric at all? I hope there is a better way than checking all existing numeric types of .net (Int32, Int16, Int64, UInt32, Double, Decimal, ...)</p>
  
  <p>//<strong>update</strong>: I managed to write a method which works pretty well. However there might be some issues with numbers of the type decimal (have not tested it yet). But it works for every other numeric type (including high numbers of Int64 or UInt64). If anybody is interested: <a href="http://pastebin.com/SD38DCL0" rel="nofollow noreferrer">code for number equality</a></p>