首页 诗词 字典 板报 句子 名言 友答 励志 学校 网站地图
当前位置: 首页 > 教程频道 > .NET > C# >

asp.net网站项目中运用Type.GetType获取对象为NULL

2013-09-06 
asp.net网站项目中使用Type.GetType获取对象为NULL类均在APP_Code文件夹中定义了一个借口:public interfac

asp.net网站项目中使用Type.GetType获取对象为NULL
类均在APP_Code文件夹中

定义了一个借口:


public interface IMethodExample
{
    string Method();
}


一个类:


public class MethodExample: IMethodExample
    {
        public string Method()
        {
            string str = " 1234567 ";
            return str;
        }
    }



在APSX.CS的Page_Load事件里


IMethodExample tt= Type.GetType("MethodExample") as IMethodExample;
Response.Write(tt == null);


输出结果True

加上命名空间也不行。

在网站项目里无法使用这个么。
[解决办法]
肯定获取不到啊,你都没有实例化一个IMethodExample对象啊
[解决办法]

IMethodExample tt = Activator.CreateInstance(Type.GetType("命名空间.MethodExample")) as IMethodExample;

热点排行