title: C# 4.0 dynamic: A potential performant solution to numeric generics?
body: <p>After coming up against this problem myself in trying to implement a generic <code>Vector2&lt;int/float/double&gt;</code> in C#, I've done a bunch of investigation into this problem, also described in this question:</p>
  
  <p><a href="https://stackoverflow.com/questions/1449865/less-generic-generics-a-possible-solution-for-arithmetic-in-c-generics">Less generic generics? A possible solution for arithmetic in C# generics</a></p>
  
  <p>These links contain some more background information and fascinating solution approaches:</p>
  
  <p><a href="https://jonskeet.uk/csharp/miscutil/usage/genericoperators.html" rel="nofollow noreferrer">https://jonskeet.uk/csharp/miscutil/usage/genericoperators.html</a></p>
  
  <p><a href="http://www.codeproject.com/KB/cs/genericnumerics.aspx" rel="nofollow noreferrer">http://www.codeproject.com/KB/cs/genericnumerics.aspx</a></p>
  
  <p>Now that C# 4.0 is out with its new versatile <code>dynamic</code> type, my question for the brilliant SO community, is this: is it a tool that could be used perhaps to build performant, generic Vector/Matrix/etc. numeric types?</p>
  
  <p>Clearly a Vector2 could be built by simply like so:</p>
  
  <pre><code>public struct Vector2
  {
      public dynamic X;
      public dynamic Y;
  
      public Vector2(dynamic x, dynamic y)
      {
          this.X = x;
          this.Y = y;
      }
  
      public static Vector2 operator+(Vector2 a, Vector2 b)
      {
          return new Vector2(a.X + b.X, a.Y + b.Y);
      }
  }
  </code></pre>
  
  <p>but with this approach we have no type constraint here, so you could make a <code>Vector2(3, 12.4572)</code>.  Is there a way that we could mix dynamic members with a type parameter <code>Vector2&lt;int&gt;</code> to perform our math operations as would be done with <code>int</code>s?</p>
  
  <p>Perhaps some form of casting could be used to ensure <code>this.X</code> is a <code>T</code>, though I don't know how that would perform.</p>