using type returned by Type.GetType() in c#

Something like this:

Type listType = typeof(List<>).MakeGenericType(customer);
IList customerList = (IList)Activator.CreateInstance(listType);

Of course you can’t declare it as

IList<customer>

because it is not defined at compile time. But List<T> implements IList, so you can use this.

Leave a Comment