代码无法找到课程

时间:2016-03-14 00:38:41

标签: c# asp.net class object namespaces

我有一个名为ContactList的类,我做了一个实例,但它声称它不存在Class在App_code文件夹中,我有其他页面,我可以访问其他类,只有这个不能工作。

Image of error

using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Data;
using System.Web.UI.WebControls;

namespace CSC237_SportsPro_Holmbeck
{
    public partial class DisplayContact : System.Web.UI.Page
    {
        private ContactList list;
        protected void Page_Load(object sender, EventArgs e)
        {
            list = ContactList.GetList();
            if (!IsPostBack)
            this.DisplayList();
        }    
        private void DisplayList()
        {
            ContactListBox.Items.Clear();
            for (int i = 0; i < list.Count; i++)
                ContactListBox.Items.Add(this.list[i].Display());
        }

2 个答案:

答案 0 :(得分:1)

正如建议所示,按ctrl + .它会显示建议列表。选择适当的命名空间或在导入部分中包含该行。

using projectFolder.App_Code;

通过这一行代码,您可以为相应的类指定命名空间。

  

Namespace在C#程序中以两种方式大量使用。首先,   .NET Framework类使用命名空间来组织其中的许多命名空间   类。其次,声明自己的命名空间可以帮助控制   大型编程项目中的类和方法名称的范围。

答案 1 :(得分:0)

  • 作为文件的名称&#34; ContactList&#34;并不意味着该类的名称是相同的。你会检查那个文件并看到该类的名称是一样的吗?
  • 可以设置为不同的命名空间,在您的情况下为App_Code.ContactList。检查它们是否在同一名称空间中。
  • 您可能将该类设置为私有。即使你没有,我认为它的默认值仍然是私密的。你可能会认为它转向公开。