<p>I need to create at runtime instances of a class that uses generics, like <code>class&lt;T&gt;</code>, without knowing previously the type T they will have, I would like to do something like that:</p>

<pre><code>public Dictionary&lt;Type, object&gt; GenerateLists(List&lt;Type&gt; types)
{
    Dictionary&lt;Type, object&gt; lists = new Dictionary&lt;Type, object&gt;();

    foreach (Type type in types)
    {
        lists.Add(type, new List&lt;type&gt;()); /* this new List&lt;type&gt;() doesn't work */
    }

    return lists;
}
</code></pre>

<p>...but I can't. I think it is not possible to write in C# inside the generic brackets a type variable. Is there another way to do it?</p>

You can't do it like that - the point of generics is mostly
compile-time
type-safety - but you can do it with reflection:
```
```
public Dictionary<Type, object> GenerateLists(List<Type> types)
{
    Dictionary<Type, object> lists = new Dictionary<Type, object>();

    foreach (Type type in types)
    {
        Type genericList = typeof(List<>).MakeGenericType(type);
        lists.Add(type, Activator.CreateInstance(genericList));
    }

    return lists;
}
```
```