我不认为
GetMethod会这样做,不,但是
GetConstructor会。
using System;using System.Reflection;class Addition{ public Addition(int a) { Console.WriteLine("Constructor called, a={0}", a); }}class Test{ static void Main() { Type type = typeof(Addition); ConstructorInfo ctor = type.GetConstructor(new[] { typeof(int) }); object instance = ctor.Invoke(new object[] { 10 }); }}编辑:是的,
Activator.CreateInstance也会工作。使用
GetConstructor,如果你想拥有的东西上更多的控制,找出参数名称等
Activator.CreateInstance是伟大的,如果你
只是 想调用构造函数,虽然。



