[Solved] having trouble with global variable


There is no such thing as global variables in C#. This will do the trick for you. You could also try the static class with static members solution to simulate something like global variables, but that still won’t be a global variable.

Try this (you’re using an attribute in the class in this solution, it will be “global” inside this class)

public class YourClass{

    private static string _input;

    public static void Main (string[] args)
    {
        Console.Write ("What is your name: ");
        _input = Console.ReadLine ();

        sayHi ();
    }

    public static string sayHi() {
        Console.WriteLine ("Hello {0}!", _input);
    }
}

5

solved having trouble with global variable