void Start()
{
ShowMainMenu("Hello Noah");
}
void ShowMainMenu (string greeting) {
Terminal.ClearScreen();
Terminal.WriteLine(greeting);
Terminal.WriteLine("What would you like to hack into?");
Terminal.WriteLine("Press 1 for the local library");
Terminal.WriteLine("Press 2 for the police station");
Terminal.WriteLine("Enter your selection:");
}
Why do we add “Hello Noah” in the variable (I think) ShowMainMenu? How does that declare that the string greeting is “Hello Noah”? Do the brackets of the first ShowMainMenu (the one in the Start function) and the brackets for the ShowMainMenu function correspond?
In C#, all methods need parentheses behind their name. ShowMainMenu is defined with a parameter meaning that the method expects data. To send data to a method, you put the expected value or object reference into the parentheses. Does that make sense so far?
A variable is a data container. In your example, "Hello Noah" is not a variable because you cannot reuse it. It is a string, just as the ShowMainMenu method expects it. This data gets assigned to the greeting variable which exists only within the scope of the ShowMainMenu method.
This would be an example with a variable:
void Start()
{
string s = "Hello Noah";
ShowMainMenu(s);
}
I named it differently on purpose to show you that you do not pass on the variable but the data the variable contains. Of course, you could name the variable greeting, too, because the name is unambiguous within the scope of the Start method.