What is the correct code to cast an object back to a generic list like so?
Type x = typeof(MyClass);
object o = new List<MyClass>();
List<x> l = o as List<x>; // Not working
EDIT:
Maybe it wasn’t all clear: The object is a list of a generic type which i don’t know at compile time.. nevertheless List has functions like “Add” i can call anyway, like:
l.Add((new MyClass() as object)) as x);
or
Do you mean
This is not possible until you use a generic class:
Usage:
Finally I got OP’s goal:
See MSDN for details.