C#Web项目抱怨一类 [英] C# web project complaining about a class
问题描述
我创建了一个新的项目(在C#中的Web项目)。
在我的项目称为APP_ code创建一个新的文件夹。
我接着添加具有以下类:
I created a new project (web project in C#). Created a new folder in my project called App_Code. I then proceeded to add a class with the following:
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using Shipper.DataLayer;
namespace Shipper.BusinessLayer
{
public static class BL
{
public static int JustSomeTest()
{
return 1;
}
}
}
在我的网页 Default.aspx的
在我后面的code的人试图做的:
And in one of my pages default.aspx
in the code behind I tried to do:
INT I = BL.JustSomeTest();
我没有得到任何智能感知,当我在 BL型。
。它说我缺少程序集或引用。或者,它会说 BL不当前上下文中的名称
。
但我必须包括一个参考,如果类文件是在同一个项目?我甚至试图建立我的项目,它在第一次产生与我的解决方案文件名的dll文件, Shipper.dll
,但只要我添加此引用它说名称BL不会在目前的情况下存在
。
I am not getting any intellisense when I type in BL.
. It says I am missing an assembly or reference. Or it will say The name BL does not exist in the current context
.
But do I have to include a reference if the class file is in the same project? I even tried to Build my project and it at first generated a dll file with the name of my solution file, Shipper.dll
but as soon as I add this reference it says The name BL does not exist in the current context
.
在我的Default.aspx页面,我试图添加一个using语句
In my default.aspx page I've tried to add a using statement
使用托运人。
但只要我做,我的空间BusinessLayer不显示...
林混淆?
But as soon as I do that my namespace BusinessLayer is not shown... Im confused?
修改
下面是Default.aspx的:
Here is default.aspx:
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using Shipper.BusinessLayer;
namespace Shipper
{
public partial class _Default : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
if (!Page.IsPostBack)
{
SetDefaults();
int i = BL.JustSomeTest();
}
}
}
}
下面是我的 BL.cs
文件:
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using Shipper.DataLayer;
namespace Shipper.BusinessLayer
{
public static class BL
{
public static int JustSomeTest()
{
return 1;
}
}
}
错误读取类型或命名空间名称
BusinessLayer 命名空间中不存在托运人(是否缺少程序集引用)?
The error reads The type or namespace name
BusinessLayerdoes not exist in the namespace Shipper (are you missing an assembly reference)?
推荐答案
您...
public static int JustSomeTest()
{
return 1;
}
...是了类的
- 你不能有单独的命名空间中定义的方法
...is out of the 'class'
- you cannot have methods defined for the namespace alone.
(从你的榜样,至少,它可能只是一个错字,但随后你需要给我们一个工作示例)
(at least from your example, it might be just a typo but then you'd need to give us a working example)
这篇关于C#Web项目抱怨一类的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!