用反射执行某个类的方法
namespace test_Console
{
public class Man
{
public void Go()
{
Console.WriteLine("GO");
}
}
class Program
{
static void Main(string[] args)
{
Go<Man>();
Console.WriteLine();
}
private static void Go<T>()
{
Type t = typeof(T);
object obj = Activator.CreateInstance(t);
MethodInfo f = t.GetMethod("Go");
f.Invoke(obj, null);
}
}
}
执行结果如下: