用了
private void a(string pClass)
{
Type t = Type.GetType(pClass, true, true);
}失败了pClass类名怎么才能实现:类名做为变量,且创建这个类?
private void a(string pClass)
{
Type t = Type.GetType(pClass, true, true);
}失败了pClass类名怎么才能实现:类名做为变量,且创建这个类?
解决方案 »
- C# Winform 事件阻止问题
- |ZYCWPF| 在WPF当中,如何给Gird的每一行,每一列统一设置Padding呢、?
- c# 如何用listview 显示文件夹的内容,主要是文件有更新实时的在列表更新!
- 求助啊?? 哪位兄台帮忙解决一下哦
- 怎么知道系统的时间到了第二天
- 进来帮我看一下问题。谢谢!
- 高手来挑战...关于代码设置
- 学c#之前 要学习c++不?
- 用Visual C#编写ASP.NET Web应用程序 遇到的低级问题!
- sql语句如何对字符串做加号操作~
- C#窗口打开后自动隐藏
- ‘Word.Tables' does not contain a definition for 'Item'(CS0117) 错误处理
object CreateObject(Type t)
{
return System.Activator.CreateInstance(t);
} protected void Page_Load(object sender, EventArgs e)
{ object o = CreateObject(typeof(Int32));
Response.Write(o.ToString());
}
{
return System.Activator.CreateInstance(t);
} protected void Page_Load(object sender, EventArgs e)
{ object o = CreateObject(typeof(Int32));
Response.Write(o.ToString());
}(慕白兄) 的正确
typeof(名).GetType().FullName
这个就是你的完整的类名,它包含你的class所在的命名空间的
http://topic.csdn.net/u/20100223/19/5959efa0-09c9-4ba3-9f88-3a58c98bde44.html System.Reflection.Assembly asm = System.Reflection.Assembly.LoadFrom("dll的路径要是全路径");
object o = asm.CreateInstance("类名");
类名也是要完整的类名,编译后的DLL也可以直接就“添加引用”,这样就可以直接new了
Type.GetType("System.String");如果是其他程序集的,需要加上dll文件名(不含.dll)。把生成的dll放到程序运行目录。以下举例将my.Entity.dll拷贝到运行目录bin/debug目录下,取User类
Type type = Type.GetType("my.Entity.User,my.Entity");留意后面的“...,my.Entity”