1 var constructors=typeof(Demo).GetConstructors(); 2 var paramsInfos=constructors[i].GetParameters();//I代表构造函数的下标 3 List<object> o = new List<object>{"1",20}; 4 constructors[i].Invoke(o.ToArray()); 5 Console.ReadLine();
1 public class Demo 2 { 3 public Demo(string name) 4 { 5 Console.WriteLine("我的名字是"+name); 6 } 7 public Demo(string name,int age) 8 { 9 Console.WriteLine("我的名字是" + name+"我今年:"+age+"了."); 10 } 11 }