how do you apply a class

hello all, I am new with C# and stuck on some coursework
I have created a class:
public class student
{ //start of class declaration
public string name="Jane Doe";
public string course="Multimedia and Internet Systems";
public string email="test@test.com";


}

how do I apply the class to a textbox so that when the user selects one of the details say name then the name will appear in the textbox.
or am i doing something completely wrong with the class
i am using MS Visual Studio .NET 2003

any help would be greatly appreciated

edit: i am using a main menu in the application, so when the user selects name from the menu it will display in the textbox


Answer this question

how do you apply a class

  • Naolin

    Everything with the class appears fine. If no runtime error is occuring then use some debugging techniques to find out why the details are not being displayed.


  • rodri_ogri

    bklare wrote:
    Everything with the class appears fine. If no runtime error is occuring then use some debugging techniques to find out why the details are not being displayed.


    runtime is occuring.

    for some reason it doesnt seem to be recognising the name, course or email.
    i get this error for each: the private field 'coursework4.Form1.student.name' is never used

  • DanielN305517

    ok thank you.

    i have another problem though is the class I have created correct because the details are not being displayed when i run the app and click on one of the menu items.

  • dba_sql

    Is this a runtime error or a compile error

    It looks like a compile error, but actually, it does not even look like an error, it looks like a warning.


  • R2ks

    It is no problem I am trying to make sure I understand what you are talking about. The errors you mention, are they occuring during the programs execution i.e. does the program stop running an say, for example, an unhandled expception has occured If not, then are they shown right after you compile the program If the second case is true then these are merely warnings. They are letting you know that you declared those strings but nowhere in the code are they actually used (besides there declarations).

    A good debugging technique to see if you are properly suscribing to menu buttons event, is in the code add a quick message box: MessageBox.Show("HERE!");
    This will let you know you made it to that area of your code (Using the debugger is a better technique but it is far more complicated to explain).




  • huabing78

    i am using a main menu for the user to select the details.
    can you use a switch case statement with a main menu

  • mahdi

    bklare wrote:
    Is this a runtime error or a compile error

    It looks like a compile error, but actually, it does not even look like an error, it looks like a warning.


    well its compiling and the app is running but, those errors are still displaying.
    it doesn't say anything about a build error.

    i'm really sorry if i am making this more confusing than it is.

  • curtKauf

    When you click a menu button, then an event is raised. In the handler for the event then you will have the code that can call the function. To create the event, I believe you can just double click the corresponding menu button in the design view and it will create the event in the code for you, which you just need to fill in with your code.


  • Srikanth Ramakrishnan

    There are many many ways to do this. One possibility:

    You will have the textbox you want the name in, well call it textBox1.

    Now just make some function in the class that allows the user to select one of the three strings. Enumerations work nicely, but we will just use plain int,

    void SelectDisplayItem(int item)
    {
    switch (item)
    {
    case 0:
    textBox1.Text = name;
    break;
    case 1:
    textBox1.Text = couse;
    break;
    case 2:
    textBox1.Text = email;
    break;
    default:
    textBox1.Text = "Invalid Selection";
    break;
    }
    }




  • how do you apply a class