为什么类型不返回值c#.net [英] why type does not return values c#.net

查看:178
本文介绍了为什么类型不返回值c#.net的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

string formname = Assembly.GetEntryAssembly().GetName().Name +." +"AddForm";
//实际上,表单名包含此字符串"DynamicProject.AddForm"
类型tp = Type.GetType(formname);
//但是tp显示空值

string formname=Assembly.GetEntryAssembly().GetName().Name+"."+"AddForm";
//actually formname contain this string "DynamicProject.AddForm"
Type tp=Type.GetType(formname);
//but tp shows null value

推荐答案

在其周围放置一个try/catch块,并在调试器下运行代码,您将确切地了解到什么.是错误的.
Put a try/catch block around it and run the code under the debugger, and you''ll find out exactly what''s wrong.


您的应用程序中是否确实存在AddForm,请检查此代码并查找错误
Is that AddForm really exist in your application, Check this code and find what the error is
Type tp=Type.GetType(formname, true);



这是用于获取类型的语法



This are the syntaxes used to get type

Type GetType(string typeName);

   Type GetType(string typeName, bool throwOnError);

   Type GetType(string typeName, bool throwOnError, bool ignoreCase);


这篇关于为什么类型不返回值c#.net的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆