c# 通过反射调用类的构造函数

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();
View Code
 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     }
View Code
原文地址:https://www.cnblogs.com/q975261413/p/5236019.html