Initialize generic object from a System.Type

Posted by CaptnCraig on Stack Overflow See other posts from Stack Overflow or by CaptnCraig
Published on 2010-05-14T03:08:26Z Indexed on 2010/05/14 3:14 UTC
Read the original article Hit count: 226

Filed under:
|

I need to create a generic type, but I do not know the type at compile time. I would like to do this:

Type t = typeof(whatever);
var list = new List<t>

this won't compile, because t is not a valid type. But it does know all about a valid type. Is there a way to dynamically create the generic list from a System.Type like this? I may need reflection, and that's ok, I am just a bit lost here.

© Stack Overflow or respective owner

Related posts about c#

Related posts about generics