C# How to create generic List with dynamic type
Given the Type typeof(Item) (defined below), how would you create a list of Items using Reflection in C#?
var type = typeof(Item); IList listOfItems = (IList)Activator.CreateInstance(typeof(List<>).MakeGenericType(type));
public class Item
{
public string Name { get; set; }
}
Comments
Post a Comment