+ 1
Why {0}
static void Main(string[] args) { string yourName; Console.WriteLine("What is your name?"); yourName = Console.ReadLine(); Console.WriteLine("Hello {0}", yourName); } The code has {0}. What for?
2 Antworten
+ 2
Including the {0} within the string will just replace it with whatever variable is given after the string which will be printed out, replacing it in this case to whatever the user enters as their name (ie. It will print "Hello" + your name). The 0 in the curly brackets just tells the function which variable should replace that part of the string, as if you had more you could replace it to {2} for example to output the third variable within that function.
0
Faisal Thank you very much!