title: C# : Get type parameter at runtime to pass into a Generic method
body: <p>The generic Method is...</p>
  
  <pre><code>    public void PrintGeneric2&lt;T&gt;(T test) where T : ITest
      {
          Console.WriteLine("Generic : " + test.myvar);
      }
  </code></pre>
  
  <p>I'm calling this from Main()...</p>
  
  <pre><code>    Type t = test2.GetType();       
      PrintGeneric2&lt;t&gt;(test2);
  </code></pre>
  
  <p>I get error "CS0246: the type or namespace name 't' could not be found" and "CS1502: best overloaded method match DoSomethingClass.PrintGeneric2&lt; t >(T) has invalid arguments"</p>
  
  <p>this is related to my previous question here: <a href="https://stackoverflow.com/questions/9664912/c-sharp-passing-a-generic-object">C# : Passing a Generic Object</a></p>
  
  <p>I've read that the generic type can't be determined at runtime, without the use of reflection or methodinfo, but I'm not very clear on how to do so in this instance.</p>
  
  <p>Thanks if you can enlighten me =)</p>