c# - 代码找不到类

标签 c# asp.net class object namespaces

我有一个名为 ContactList 的类,我创建了一个实例,但它声称它不存在,该类在 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());
        }

最佳答案

正如建议所说,按 ctrl + .它将显示建议列表。选择适当的命名空间或在导入部分包含该行。
using projectFolder.App_Code;
通过这一行代码,您可以为相应的类指定命名空间。

Namespace are heavily used within C# programs in two ways. Firstly, the .NET Framework classes use namespaces to organize its many classes. Secondly, declaring your own namespaces can help control the scope of class and method names in larger programming projects.

关于c# - 代码找不到类,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/35977779/

相关文章:

c# - cargo 崇拜编程 : locking on System. 对象

javascript - 如何在asp.net中逐行跟踪java脚本程序

c++ - 使用 4/5 舍入规则对数字进行舍入

c# - 如何检查设备是否已加入 AD 或 Azure AD 加入/注册?

c# - Linq查询获取最后一条记录

c# - 如何创建已在后端 HTML 表和 ASP.NET 中的 div 中创建的 onserverclick 事件

c# - 在 ASP.NET MVC 5 中,在我应用迁移来更改 MODEL 类后,它也会更改我的 View .cshtml 文件吗?

asp.net - Visual Studio Asp.Net 开发服务器真的是多线程的吗?

css - 将不同的 css 样式类分配给已经存在的 css 类

C++双向链表 - 使用pop_back()从尾部删除元素