tags:

views:

122

answers:

4
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(IDnumber.Name);   
                    myData.AppendLine(": ");   
                    myData.AppendLine(IDnumber.ID);   
                    myData.AppendLine(IDnumber.year);   
                    myData.AppendLine(IDnumber.class1);   
                    myData.AppendLine(IDnumber.class2);   
                    myData.AppendLine(IDnumber.class3);   
                    myData.AppendLine(IDnumber.class4);  
                    MessageBox.Show(myData);
                }

            public string GetDataFromNumber(string ID)
            {

               foreach (IDnumber idCandidateMatch in IDnumbers)  

            { 

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

    }
}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(IDnumber.Name);   
                    myData.AppendLine(": ");   
                    myData.AppendLine(IDnumber.ID);   
                    myData.AppendLine(IDnumber.year);   
                    myData.AppendLine(IDnumber.class1);// i get it for all of these   
                    myData.AppendLine(IDnumber.class2);   
                    myData.AppendLine(IDnumber.class3);   
                    myData.AppendLine(IDnumber.class4);  
                    MessageBox.Show(myData);
                }

            public string GetDataFromNumber(string ID)
            {

               foreach (IDnumber idCandidateMatch in IDnumbers)  

            { 

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

    }
}
A: 

The static method should not be referencing itself, it should be referencing the IDnumber that you are passing into it like so:

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);// i get it for all of these   
    myData.AppendLine(myNum.class2);
    myData.AppendLine(myNum.class3);
    myData.AppendLine(myNum.class4);
    MessageBox.Show(myData.ToString());
}
Jason Webb
tried that it says static field or property cannot be assigned in an object initializer!
JB
Hey BigJason, I might be wrong, but, without running a test, I would say that your suggestion would solve compiling error, but it would probably not help JB (author of the question) because when you make properties static then there is only one instance of that property, and all instances of that class will have the same propertz values (IDnumbers[0], IDnumbers[1], IDnumbers[2]...)
this doesnt work either...
JB
Sorry I should have read the code more. I have fixed my example above. Hope that is more helpful.
Jason Webb
preciate BigJason, that helped out!
JB
i now get the same thing on my if statement however!
JB
nevermind Got It..
JB
A: 

Well its a lot of code but heres an example

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(IDnumber.Name);    
                myData.AppendLine(": ");    
                myData.AppendLine(IDnumber.ID);    
                myData.AppendLine(IDnumber.year);    
                myData.AppendLine(IDnumber.class1);// i get it for all of these    
                myData.AppendLine(IDnumber.class2);    
                myData.AppendLine(IDnumber.class3);    
                myData.AppendLine(IDnumber.class4);   
                MessageBox.Show(myData); 
            } 

Your method is static but the class containing the members you are refering to are not, it doesn't work that way because that method will never belong to a certain instance.

Jonas B
A: 
 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);
 }
Gregoire
A: 

One solution is to do this:

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

instead of:

       foreach (IDnumber idCandidateMatch in IDnumbers)  

        { 

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

Because Name (and other properties) are not static.

The problem is in lines like this:

IDnumber.[property]

like for example

IDnumber.ID

or

IDnumber.Name

because ID, Name... and others are not static. The solutions is to replace class name with your instance variable in all relevant lines:

like

idCandidateMatch.ID

idCandidateMatch.Name

... (see code above)

Please note also that you use different case for variable name here:

        foreach (IDnumber *idCandidateMatch* in IDnumbers)  

and here:

        if (*IDCandidateMatch*.ID == ID)

C# is case sensitive and that should not work (unless i missed something in your source code:)

Thanks zarko, that helped!
JB