反射
var a = Assembly.GetExecutingAssembly(); Type type = a.GetType("CLRTest.ReflectClass"); var instance = Activator.CreateInstance(type); var method= type.GetMethod("Add"); method.Invoke(instance, new object[] { 1, 2 });
dynamic
var a= Assembly.GetExecutingAssembly(); Type type = a.GetType("CLRTest.ReflectClass"); dynamic instance=Activator.CreateInstance(type); var sum=instance.Add(1,2);
语法相对简化一些,性能上还未测试。