日期:2014-05-18 浏览次数:20753 次
static void Main() { object intList = MakeList(typeof(int), 1, 2, 3); object strList = MakeList(typeof(string), "sdfd", "fet"); //List<int> foreach(object obj in (System.Collections.IEnumerable)intList) Console.WriteLine(obj); //List<string> foreach(object obj in (System.Collections.IEnumerable)strList) Console.WriteLine(obj); } static object MakeList(Type t, params object[] items) { Type type = typeof(List<>).MakeGenericType(t); object list = Activator.CreateInstance(type); System.Collections.IList ilist = list as System.Collections.IList; foreach (object o in items) ilist.Add(o); return list; }