C# 不包含GetDataFromNumber的定义,但我已定义它?

C# 不包含GetDataFromNumber的定义,但我已定义它?,c#,winforms,C#,Winforms,说它不包含它的定义,但在我的GetSchedule.cs文件中定义了它 public void button2_Click(object sender, System.EventArgs e) { string text = textBox1.Text; Mainform = this; this.Hide(); GetSchedule myScheduleFinder = new GetSchedule(); string result = mySc

说它不包含它的定义,但在我的GetSchedule.cs文件中定义了它

public void button2_Click(object sender, System.EventArgs e)
{
    string text = textBox1.Text;
    Mainform = this;

    this.Hide();

    GetSchedule myScheduleFinder = new GetSchedule();
    string result = myScheduleFinder.GetDataFromNumber(text);// says there is no definition
    if (!string.IsNullOrEmpty(result))
    {
        MessageBox.Show(result);
    }
    else
    {
        MessageBox.Show("Enter A Valid ID Number!");
    }
}
GetSchedule类

公共课程表 { 公众假期表 { IDnumber[]IDnumbers=新的IDnumber[3]; IDnumbers[0]=新IDnumber{Name=Joshua Banks,ID=900456317,year=Senior,class1=TEET 4090,class2=TEET 3020,class3=TEET 3090,class4=TEET 4290}; IDnumbers[1]=新的IDnumber{Name=Sean Ward,ID=900456318,year=Junior,class1=ENGNR 4090,class2=ENGNR 3020,class3=ENGNR 3090,class4=ENGNR 4290}; IDnumbers[2]=新的IDnumber{Name=Terrell Johnson,ID=900456319,年级=大二,班级1=BUS 4090,班级2=BUS 3020,班级3=BUS 3090,班级4=BUS 4290}

public string GetDataFromNumber(string ID)//defined here
{

    foreach (IDnumber IDCandidateMatch in IDnumbers)
    {

        if (IDCandidateMatch.ID == ID)
        {
            StringBuilder myData = new StringBuilder();
            myData.AppendLine(IDCandidateMatch.Name);
            myData.AppendLine(": ");
            myData.AppendLine(IDCandidateMatch.ID);
            myData.AppendLine(IDCandidateMatch.year);
            myData.AppendLine(IDCandidateMatch.class1);
            myData.AppendLine(IDCandidateMatch.class2);
            myData.AppendLine(IDCandidateMatch.class3);
            myData.AppendLine(IDCandidateMatch.class4);
            //return myData;
            return myData.ToString();
        }
    }
    return "";
}
} }

    }
    public class IDnumber
    {
        public string Name { get; set; }
        public string ID { get; set; }
        public string year { get; set; }
        public string class1 { get; set; }
        public string class2 { get; set; }
        public string class3 { get; set; }
        public string class4 { get; set; }


       public static void ProcessNumber(IDnumber myNum)
            {
                StringBuilder myData = new StringBuilder();
                myData.AppendLine(myNum.Name);   
                myData.AppendLine(": ");
                myData.AppendLine(myNum.ID);
                myData.AppendLine(myNum.year);
                myData.AppendLine(myNum.class1);
                myData.AppendLine(myNum.class2);
                myData.AppendLine(myNum.class3);
                myData.AppendLine(myNum.class4);  
                MessageBox.Show(myData.ToString());
            }

        public string GetDataFromNumber(string ID)
        {
            IDnumber[] IDnumbers = new IDnumber[3];
            foreach (IDnumber IDCandidateMatch in IDnumbers)  

            { 

                if (IDCandidateMatch.ID == ID)
                {
                 StringBuilder myData = new StringBuilder();
                 myData.AppendLine(IDCandidateMatch.Name);   
                 myData.AppendLine(": ");
                 myData.AppendLine(IDCandidateMatch.ID);
                 myData.AppendLine(IDCandidateMatch.year);
                 myData.AppendLine(IDCandidateMatch.class1);
                 myData.AppendLine(IDCandidateMatch.class2);
                 myData.AppendLine(IDCandidateMatch.class3);
                 myData.AppendLine(IDCandidateMatch.class4);  
                 //return myData;
                 return myData.ToString();
    }
}
return "";

}

是否确保GetDataFromNumber在类定义中,而不是在右括号之后?

检查GetSchedule类是否位于您试图从中调用它的同一命名空间中,或者它是否被引用

    }
    public class IDnumber
    {
        public string Name { get; set; }
        public string ID { get; set; }
        public string year { get; set; }
        public string class1 { get; set; }
        public string class2 { get; set; }
        public string class3 { get; set; }
        public string class4 { get; set; }


       public static void ProcessNumber(IDnumber myNum)
            {
                StringBuilder myData = new StringBuilder();
                myData.AppendLine(myNum.Name);   
                myData.AppendLine(": ");
                myData.AppendLine(myNum.ID);
                myData.AppendLine(myNum.year);
                myData.AppendLine(myNum.class1);
                myData.AppendLine(myNum.class2);
                myData.AppendLine(myNum.class3);
                myData.AppendLine(myNum.class4);  
                MessageBox.Show(myData.ToString());
            }

        public string GetDataFromNumber(string ID)
        {
            IDnumber[] IDnumbers = new IDnumber[3];
            foreach (IDnumber IDCandidateMatch in IDnumbers)  

            { 

                if (IDCandidateMatch.ID == ID)
                {
                 StringBuilder myData = new StringBuilder();
                 myData.AppendLine(IDCandidateMatch.Name);   
                 myData.AppendLine(": ");
                 myData.AppendLine(IDCandidateMatch.ID);
                 myData.AppendLine(IDCandidateMatch.year);
                 myData.AppendLine(IDCandidateMatch.class1);
                 myData.AppendLine(IDCandidateMatch.class2);
                 myData.AppendLine(IDCandidateMatch.class3);
                 myData.AppendLine(IDCandidateMatch.class4);  
                 //return myData;
                 return myData.ToString();
    }
}
return "";
从更新后的帖子来看,函数GetDataFromNumber位于一个名为IDNumber的类中—这就是问题所在吗

尝试:


问题是因为您正在创建web表单并将代码从一个页面复制到另一个页面。在执行此操作时,必须小心并确保不更改页面中的第一个指令。它告诉web应该在代码页后面查找什么,应该在哪里找到定义和代码逻辑。出现此问题的原因是,当您从一个页面复制并粘贴到另一个页面时,它为另一个页面带来了指令,而您很可能没有在页面中定义要调用的函数。因此,请确保您将网页的第一行更改为指向正确的.cs文件及其继承的类。

抱歉,您需要重新表述您的问题,因为它一点也不清楚。对不起,我收到一个错误,说GetDataFromNumber未定义,并且不接受类型为的第一个参数…但是GetDataFromNumber在另一个.cs文件的第二组代码中使用/定义…我该如何更正此错误!?!你真的有一个叫做GetSchedule的类吗?如果是这样的话,在问题中包含这个定义可能会有帮助。是的,我有一个名为GetSchedule的类。我所有的.cs文件都在同一个项目中,在同一个名称空间Eagle_Eye_class_Finder下……好的,我已经更新了我的答案。很难从你发布的代码中分辨出来,但看起来你的函数不在你正在实例化的类中是的,你是对的,它在IDnumber类中,但它是公共的,所以我不应该在整个项目中使用它吗?是的,但你必须实例化正确的类。如果你实例化IDnumber类,那么你就可以用它来调用它了。好吧,这是有意义的,我对C有点陌生,有没有关于如何以正确的方式实例化它的帮助???
IDnumber myNumber = new IDnumber();
myNumber.GetDataFromNumber(text);