bigt
bigt

Reputation: 7

Code cant find class

I have a class called ContactList that i make a instance of, but it claims it doesnt exist the Class is in the App_code folder and i have other pages that i could access other classes from, only this one wont work.

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());
        }

Upvotes: 0

Views: 101

Answers (2)

Pecheneg
Pecheneg

Reputation: 808

  • Being the name of the file "ContactList" doesn't mean the name of the class is the same. Would you check that file and see the name of the class is the same?
  • It could be set to a different namespace, in your case App_Code.ContactList. Check they both in the same namespace.
  • You might be set the class as private. Even you didn't, I think it's default value is still private. You might consider it turning to public.

Upvotes: 0

sujith karivelil
sujith karivelil

Reputation: 29036

As the suggestions says, Press ctrl + . it will show the suggestion list. select the appropriate namespace or include the line in the import sesction.

using projectFolder.App_Code;

Through this single line of code you are specifying the Namespace for the corresponding class.

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.

Upvotes: 1

Related Questions