title: How to set a default type for T in a static generic method?
body: <p>I am working with my own custom stacks class, and I am trying to create a generic method for creating a new stack(a generic object). I work a lot with stacks that are type int, and only occasionally need other types. Can I set the defult Type of T to int?</p>
  
  <p>Here is the method:</p>
  
  <pre class="lang-cs prettyprint-override"><code>public static Stack&lt;T&gt; newStack&lt;T&gt;(int length)
  {
      Stack&lt;T&gt; s = new Stack&lt;T&gt;();
      for (int i = 0; i &lt; length; i++)
      {
          Console.WriteLine("print num");
          string input = Console.ReadLine();
          T value = (T)Convert.ChangeType(input, typeof(T));
          s.Push(value);
      }
      return s;
  }
  </code></pre>
  
  <p>I want to use the method like this:</p>
  
  <pre><code>newStack(5);//defult int type
  </code></pre>
  
  <p>and for any other type</p>
  
  <pre><code>newStack&lt;string&gt;(5)
  </code></pre>
  
  <p>Can anybody help? Thanks.</p>