0

我在我的网站中创建了一个文件夹 asp.net C# usindg VS'10 ,,

现在我在该文件夹中添加了一个类,其命名空间如下:

using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;

namespace ThreeTierSample.BLL
{
  /// <summary>
  /// Summary description for Student
  /// </summary>
public class Student
{
    public Student()
    {
        //
        // TODO: Add constructor logic here
        //
    }


    public void insert()
    { 

    }
  }

}

我想将此名称空间用于文件后面的代码中,因为我试图将名称空间包含在语句中:

using ThreeTierSample.BLL

但问题是它不允许我添加这个命名空间,即使它没有显示在智能中。

帮我解决这个问题。

下面是我的项目层次结构的屏幕截图:

在此处输入图像描述

4

2 回答 2

0

试试这个:

using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using ThreeTierSample.BLL;

namespace ThreeTierSample.BLL
{
public class Student
{
    public Student()
    {
    } 
    public void insert()
    {     
    }
  }
}

public class TestingClass
{
Student myStudent = new Student();  //  THIS IS OUTSIDE THE ThreeTierNamespace
                                    //  and will work                                      

}

您可能将三层命名空间嵌套在另一个命名空间中,这就是为什么它没有出现在我们的智能中

于 2014-02-04T06:19:19.970 回答
0

考虑到您的学生班级位于同一解决方案的不同项目中,并且您想在其他项目中使用该班级,假设您拥有所有 UI 的 Web 项目。

所以我们必须在一个解决方案中进行项目。

  1. 学生.BLL
  2. 学生网

要解决您的问题,您必须将Student.BLL项目作为参考添加到Student.Web项目中。

以下是将项目添加为参考的步骤。:

  1. 右键单击 Student.Web 项目
  2. 选择添加 -> 参考
  3. 将显示一个弹出窗口
  4. 在该弹出窗口的右侧面板中,选择解决方案
  5. 在中间面板中,您的项目列表将显示。从那里选择 Student.BLL 并单击确定,如下所述:

在此处输入图像描述

现在您可以使用命名空间访问您的类。

注意:我在您的快照中观察到您编写了ThreeTierSamle.BLL而不是ThreeTierSample.BLL (您在'Sample'中忘记了'p ' )

于 2014-02-04T06:20:20.057 回答