C# 我不知道';我不能上课
我已经创建了名为rsscolection的类 我想在Global.ascx文件中这样使用它C# 我不知道';我不能上课,c#,asp.net,C#,Asp.net,我已经创建了名为rsscolection的类 我想在Global.ascx文件中这样使用它 namespace RSSHandler { public class Global : System.Web.HttpApplication { protected void Application_Start(object sender, EventArgs e) { RSSCollection.checkRSS();
namespace RSSHandler
{
public class Global : System.Web.HttpApplication
{
protected void Application_Start(object sender, EventArgs e)
{
RSSCollection.checkRSS();
}
}
}
但是VisualStudio告诉我“名称”RSSCollection“在当前上下文中不存在”
问题出在哪里?两个班级都是公共的
更新:这是代码的结构
如果rsscolection.cs文件位于App_code文件夹中,则将其生成操作设置为编译而不是内容。在此之后,通过临时注释行
RSSHandler.rsscolection.checkRSS()来构建项目然后像RSSHandler.rsscolection.checkRSS()一样访问它代码>
如果它们在同一个名称空间中,并且方法是静态的,那么应该可以正常工作。项目编译成功吗?您提供的看起来有效。您可以添加解决方案资源管理器的屏幕截图吗?可能是vs出现了错误,请尝试清理解决方案,重新启动vs并删除缓存。代码看起来fine@CodeCaster它返回编译错误您根本没有显示的内容中有错误。右键单击文件属性->构建Action@CodeCaster根据你的说法。我已经考验了你的目的。在“Rshandler”之后,visual studio看不到任何“应用程序代码”,这是不公平的。VS只查看全局文件@DotFreelorer您需要在将build action设置为compile之后构建项目,然后您将能够访问。在全局中临时注释行。asax@RahulNikate现在太多的类和名称空间无法访问,如“System.ServiceModel”
namespace RSSHandler
{
public class Global : System.Web.HttpApplication
{
protected void Application_Start(object sender, EventArgs e)
{
RSSCollection.checkRSS();
}
}
}
namespace RSSHandler
{
public class RSSCollection
{
public static void checkRSS()
{
...
}
}
}
namespace RSSHandler
{
public class Global : System.Web.HttpApplication
{
protected void Application_Start(object sender, EventArgs e)
{
RSSHandler.RSSCollection.checkRSS();
}
}
}