title: Using Parse Method with Generic Type?
body: <p>Straight to the code:</p>
  
  <pre><code>class ArithmeticExpressionParser&lt;T&gt; : Parser
  {
      T num1, num2;
  
      /* ......... */
  
      void ParseNumber()
      {
          string temp = String.Empty;
  
          while (char.IsDigit(PeekNextToken()))
          {
              GetNextToken();
              temp += Token;
          }
  
          num1 = T.Parse(temp);  // &lt;&lt;&lt; the problem
      }
  </code></pre>
  
  <p>Basically, if I was using an <code>int</code> or <code>double</code> I would have just use <code>int.Parse</code> etc. I've tried casting <code>num1 = (T)temp;</code> , which didn't work. How can I do this without having to write a custom <code>string</code> to <code>T</code> function?</p>