第一种从构造函数创建对象
objecto=null;
System.Typet=System.Type.GetType(this.Type);
constructor=t.GetConstructor(newType[0]);//t.GetConstructor(Type.EmptyTypes)也可以
o=constructor.Invoke(null);
System.Typet=System.Type.GetType(this.Type);
constructor=t.GetConstructor(newType[0]);//t.GetConstructor(Type.EmptyTypes)也可以
o=constructor.Invoke(null);
第二种反射的静态方法
objecto=null;
System.Typet=System.Type.GetType(this.Type);
o=System.Activator.CreateInstance(t,true);
System.Typet=System.Type.GetType(this.Type);
o=System.Activator.CreateInstance(t,true);
Activator 是包含特定的方法,用以在本地或从远程创建对象类型,或获取对现有远程对象的引用。
这两种方法有什么区别呢?如有高人路过请给予指点
本文探讨了两种在C#中创建对象的方法:通过构造函数和使用Activator类的静态方法,并邀请读者讨论两者之间的差异。
2285

被折叠的 条评论
为什么被折叠?



