conor
conor

Reputation: 5

Calling a class

How would I go about calling a function from another class in a if statement. For example i have a menu and I want to be able to to display the user choice:

namespace _5049COMP_OO
{
class Interface
{


     public string menuChoice;

    //This creates the loadup menu.
    public void menu()
    {

        DrawLine();
        Console.Write("                       Welcome to BOSS eAuctions!                               ");
        DrawLine();
        Console.WriteLine("1. Browse");
        Console.WriteLine("2. Login");
        Console.WriteLine("3. Register");
        Console.WriteLine(" ");
        Console.WriteLine(" ");
        Console.WriteLine(" ");
        Console.WriteLine("4. Quit                                                                     ");

        DrawLine();
        Console.Write("Please select on of the options:");
        menuChoice = Console.ReadLine();
        DrawLine();


    }


    // Create the login menu
    public void LoginMenu(string username, string password)
    {

        DrawLine();
        Console.Write("                          Login!                                                 ");
        DrawLine();
        Console.WriteLine("Username:");
        Console.WriteLine("Password");
        username = Console.ReadLine();
        password = Console.ReadLine();
        DrawLine();
        DrawLine();
    }

I want the statment in "Public void Choice()

 namespace _5049COMP_OO
 { 
class Functions
{

    public void Choice()
    {
    }
   }
  }      

Upvotes: 0

Views: 148

Answers (1)

colin-higgins
colin-higgins

Reputation: 1117

You need an instance of the class or it needs to be a static method.

At the top of your Interface file, add a using statement for the Functions namespace.

If you make Choice() a static method, you can do

Functions.Choice();

Otherwise you'll need

var f = new Functions();
f.Choice();

Upvotes: 4

Related Questions