无法将类组织到App_Code文件夹中的名称空间中 [英] Organizing classes into namespace in the App_Code folder not working as expected
问题描述
我为我的Web项目创建了几个类,并将它们存储在App_Code文件夹中.我不想将所有类都存储在顶层(没有名称空间),但希望将它们组织到名称空间中.到目前为止,这似乎是不可能的,因为当我使用"using XXXX;"时,名称空间声明,它仍然无法在文件后面的代码中找到正确的类.我可能做错了什么?
I have a couple of classes that I have created for my web project and I am going to store them in the App_Code folder. I don't want to store all the classes in the top level (no namespace) but want to organize them into namespaces. So far this does not seem possible because when I use the "using XXXX;" namespace statement it still can't find the right class in my code behind files. What could I be doing incorrectly?
例如,我有
namespace foo
{
public class bar
{
}
}
然后在我的default.aspx页面后面的代码中
Then in my code behind page for default.aspx I have
.
.
.
using foo
public partial class _Default : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
bar NewBar = new bar();
}
}
以上对我来说不起作用
foo.bar NewBar = new foo.bar();
有人知道我在做什么错吗?
Does anyone have any idea what I am doing wrong?
好的,所以我已经安装了Visual Studio 2005 SP 1,并尝试将其转换为Web应用程序而不是网站.仍然没有运气.
Okay, so I have installed Visual Studio 2005 SP 1 and tried to convert it to a Web application and not a web site. STILL no luck.
推荐答案
我已经弄清楚了.我真的很傻抱歉,很抱歉.这是因为我的名称空间和类名称相同,因此无法区分,需要完全限定的名称.更改班级名称后,一切都会按预期进行.
I have figured it out. I am really stupid. Sorry for the worry. It was because I had the namespace and the class name the same so it could not differentiate and needed the fully qualified name. As soon as I changed the class name everything worked as expected.
这篇关于无法将类组织到App_Code文件夹中的名称空间中的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!