I want to create an instance of type t with reflection, that is
Type t = typeof(string);
string s = (t)Activator.CreateInstance(t); // this fails because of convertion
string s = Activator.CreateInstance(t) as t // also fails
Is there a way to perform such a convertion?
Thanks.
Yes. You have to convert to
string, not tot. You may want a generic method, alternatively:As things stand you are attempting to cast an object that is actually an instance of
System.Stringto typeSystem.Type…