title: cast with a Type variable
body: <p>The below code won't work, I wanted to know how I can dynamically cast an instance to a type determined at runtime?</p>
  
  <p>Convert.ChangeType() returns an Object that still needs to be cast. So does all attempts to Invoke() a GetConstructor() or Activator.CreateInstance(), see below. At some point I need to explicitly cast in code, I'm hoping to avoid it or push it out as far as possible.</p>
  
  <pre><code>Type type = Type.GetType ("RandomChildClass");
  Object obj = Activator.CreateInstance (type, new Object[]{ "argument" });
  var instance = (type)obj;
  </code></pre>
  
  <p>I know I can create a method to accept &lt; T >, but I'd still have the same problem of not knowing how to call it with a dynamic random type
  <a href="https://stackoverflow.com/questions/972636/casting-a-variable-using-a-type-variable">Casting a variable using a Type variable</a></p>