c# - How would I define "GetDataFromNumber" so that my class contains a definition? -


my code gets error saying:

'eagle_eye_class_finder.getschedule' not contain definition 'getdatafromnumber' , no extension method 'getdatafromnumber'.

using system; using system.io; using system.data; using system.text; using system.drawing; using system.data.oledb; using system.collections; using system.windows.forms; using system.componentmodel; using system.drawing.printing; using system.collections.generic;  namespace eagle_eye_class_finder {      /// form entry form, first form user see when app run.     ///       public class form1 : system.windows.forms.form     {         private system.windows.forms.textbox textbox1;         private system.windows.forms.progressbar progressbar1;         private system.windows.forms.picturebox picturebox1;         private system.windows.forms.button button2;         private system.windows.forms.datetimepicker datetimepicker1;         private icontainer components;         private timer timer1;         private bindingsource form1bindingsource;         public static form mainform = null;          // creates new instance of second form         yourclassschedule secondform = new yourclassschedule();          public form1()         {             initializecomponent();              // todo: add constructor code after initializecomponent call          }          /// clean resources being used.          protected override void dispose(bool disposing)         {             if (disposing)             {                 if (components != null)                 {                     components.dispose();                 }             }             base.dispose(disposing);         }          #region windows form designer generated code         /// <summary>         /// required method designer support - not modify         /// contents of method code editor.         /// </summary>         private void initializecomponent()         {             this.components = new system.componentmodel.container();             system.componentmodel.componentresourcemanager resources = new system.componentmodel.componentresourcemanager(typeof(form1));             this.textbox1 = new system.windows.forms.textbox();             this.progressbar1 = new system.windows.forms.progressbar();             this.picturebox1 = new system.windows.forms.picturebox();             this.button2 = new system.windows.forms.button();             this.datetimepicker1 = new system.windows.forms.datetimepicker();             this.timer1 = new system.windows.forms.timer(this.components);             this.form1bindingsource = new system.windows.forms.bindingsource(this.components);             ((system.componentmodel.isupportinitialize)(this.picturebox1)).begininit();             ((system.componentmodel.isupportinitialize)(this.form1bindingsource)).begininit();             this.suspendlayout();             //              // textbox1             //              this.textbox1.backcolor = system.drawing.systemcolors.activecaption;             this.textbox1.databindings.add(new system.windows.forms.binding("text", this.form1bindingsource, "text", true, system.windows.forms.datasourceupdatemode.onvalidation, null, "900456317"));             this.textbox1.location = new system.drawing.point(328, 280);             this.textbox1.name = "textbox1";             this.textbox1.size = new system.drawing.size(208, 20);             this.textbox1.tabindex = 2;             this.textbox1.textchanged += new system.eventhandler(this.textbox1_textchanged);             //              // progressbar1             //              this.progressbar1.location = new system.drawing.point(258, 410);             this.progressbar1.marqueeanimationspeed = 10;             this.progressbar1.name = "progressbar1";             this.progressbar1.size = new system.drawing.size(344, 8);             this.progressbar1.tabindex = 3;             this.progressbar1.click += new system.eventhandler(this.progressbar1_click);             //              // picturebox1             //              this.picturebox1.backcolor = system.drawing.systemcolors.controllightlight;             this.picturebox1.borderstyle = system.windows.forms.borderstyle.fixed3d;             this.picturebox1.image = ((system.drawing.image)(resources.getobject("picturebox1.image")));             this.picturebox1.location = new system.drawing.point(680, 400);             this.picturebox1.name = "picturebox1";             this.picturebox1.size = new system.drawing.size(120, 112);             this.picturebox1.tabindex = 4;             this.picturebox1.tabstop = false;             this.picturebox1.click += new system.eventhandler(this.picturebox1_click);             //              // button2             //              this.button2.font = new system.drawing.font("mistral", 15.75f, system.drawing.fontstyle.regular, system.drawing.graphicsunit.point, ((byte)(0)));             this.button2.image = ((system.drawing.image)(resources.getobject("button2.image")));             this.button2.location = new system.drawing.point(699, 442);             this.button2.name = "button2";             this.button2.size = new system.drawing.size(78, 28);             this.button2.tabindex = 5;             this.button2.text = "ok";             this.button2.click += new system.eventhandler(this.button2_click);             //              // datetimepicker1             //              this.datetimepicker1.location = new system.drawing.point(336, 104);             this.datetimepicker1.name = "datetimepicker1";             this.datetimepicker1.size = new system.drawing.size(200, 20);             this.datetimepicker1.tabindex = 6;             this.datetimepicker1.valuechanged += new system.eventhandler(this.datetimepicker1_valuechanged);             //              // timer1             //              this.timer1.tick += new system.eventhandler(this.timer1_tick);             //              // form1bindingsource             //              this.form1bindingsource.datasource = typeof(eagle_eye_class_finder.form1);             //              // form1             //              this.acceptbutton = this.button2;             this.autoscalebasesize = new system.drawing.size(5, 13);             this.backgroundimage = ((system.drawing.image)(resources.getobject("$this.backgroundimage")));             this.backgroundimagelayout = system.windows.forms.imagelayout.stretch;             this.clientsize = new system.drawing.size(856, 556);             this.controls.add(this.datetimepicker1);             this.controls.add(this.button2);             this.controls.add(this.picturebox1);             this.controls.add(this.progressbar1);             this.controls.add(this.textbox1);             this.name = "form1";             this.text = "eagle eye class finder";             this.load += new system.eventhandler(this.form1_load);             ((system.componentmodel.isupportinitialize)(this.picturebox1)).endinit();             ((system.componentmodel.isupportinitialize)(this.form1bindingsource)).endinit();             this.resumelayout(false);             this.performlayout();          }         #endregion          /// main entry point application.          [stathread]         static void main()         {             application.run(new form1());          }          public void form1_load(object sender, system.eventargs e)         {           }          public void textbox1_textchanged(object sender, system.eventargs e)         {             //allows numbers entered in textbox             string str = textbox1.text.trim();             double num;             bool isnum = double.tryparse(str, out num);              if (isnum)                  console.readline();              else                 messagebox.show("enter valid id number!");                                        }          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);<<<-----my problem              if (!string.isnullorempty(result))             {                 messagebox.show(result);             }             else             {                 messagebox.show("enter valid id number!");             }         }           public void datetimepicker1_valuechanged(object sender, system.eventargs e)         {          }          public void picturebox1_click(object sender, system.eventargs e)         {          }          public void progressbar1_click(object sender, eventargs e)         {             //this.progressbar1 = new system.progressbar1();             //progressbar1.maximum = 200;             //progressbar1.minimum = 0;             //progressbar1.step = 20;          }          private void timer1_tick(object sender, eventargs e)         {             //if (progressbar1.value >= 200 )             //{             //progressbar1.value = 0;             //}             //return;             //}              //progressbar1.value != 20;          }          }      } 

my schedule class:

using system; using system.io; using system.data; using system.text; using system.drawing; using system.data.oledb; using system.collections; using system.componentmodel; using system.windows.forms; using system.drawing.printing; using system.collections.generic;

namespace eagle_eye_class_finder {

public class getschedule {     public getschedule()     {         idnumber[] idnumbers = new idnumber[3];         idnumbers[0] = new idnumber() { name = "joshua banks", id = "900456317", year = "senior", class1 = "teet 4090", class2 = "teet 3020", class3 = "teet 3090", class4 = "teet 4290" };         idnumbers[1] = new idnumber() { name = "sean ward", id = "900456318", year = "junior", class1 = "engnr 4090", class2 = "engnr 3020", class3 = "engnr 3090", class4 = "engnr 4290" };         idnumbers[2] = new idnumber() { name = "terrell johnson", id = "900456319", year = "sophomore", class1 = "bus 4090", class2 = "bus 3020", class3 = "bus 3090", class4 = "bus 4290" };      }     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 ""; 

} }

} 

}

your getdatafromnumber method non-static method inside idnumber inner class itself, hence can accessed idnumber object e.g idnumbers[0].getdatafromnumber(text);

you move getdatafromnumber method out of idnumber class , getschedule class instead.


Comments

Popular posts from this blog

javascript - Enclosure Memory Copies -

php - Replacing tags in braces, even nested tags, with regex -