这是完整的代码,你直接建一个console工程,把代码copy进去,修改命名空间为ConsoleApplication3即可。using System;
using System.Reflection;namespace ConsoleApplication3
{
/// <summary>
/// Summary description for Class1.
/// </summary>
class Class1
{
/// <summary>
/// The main entry point for the application.
/// </summary>
[STAThread]
static void Main(string[] args)
{
Assembly asm = Assembly.GetExecutingAssembly();
Type[] typelist = asm.GetTypes();
Type t = asm.GetType("ConsoleApplication3.Class2");
object obj = Activator.CreateInstance(t);
FieldInfo fi = t.GetField("Hello");
object hello = fi.GetValue(obj);
string s = "";
}
} class Class2
{
public static string Hello = "World";
}
}