實際上這個不是完全可以的

這個是可以的:
MyClass.Animal animal = new MyClass.Wolf();
MyClass.Wolf wolf = animal as MyClass.Wolf;
wolf.Eat(); //但是-> "I eat like a wolf"

Reflection sample, but still cannot make impossible to possible:

System.Reflection.Assembly r = System.Reflection.Assembly.LoadFrom(@"C:\MyProjects\TEST\Reflection\Reflection\bin\Debug\MyClass.dll");
Type[] ts = r.GetTypes();
foreach (Type t in ts)
{
if (t.Name == "Animal")
{
MyClass.MyClass.Animal animal = new MyClass.MyClass.Wolf();
MyClass.MyClass.Animal wolf = Activator.CreateInstance(t) as MyClass.MyClass.Animal;
wolf.Eat();
Console.ReadLine();
}
}

所有跟帖: 

實際上是要HACK V-TABLE,我也沒搞出來,也沒資料找 -牛牛哥- 給 牛牛哥 發送悄悄話 牛牛哥 的博客首頁 (0 bytes) () 09/14/2009 postreply 19:15:51

請您先登陸,再發跟帖!