0
Why {0} is needed in this? Console.WriteLine("Hello {0}", name);
5 odpowiedzi
+ 9
Console.WriteLine() supports placeholders. You can write as many placeholders as you want in the text, and then you list the variables that go in those spaces. It generally looks neater than concatenating everything.
Ex:
Console.WriteLine("{0} {1} {2}", x, y, z);
//as opposed to
Console.WriteLine(x + " " + y + " " + z);
+ 5
You're welcome! ^_^
+ 1
its not limited to Console.WriteLine( );
'substitution arguments' are a feature of the c# language and work in many methods
+ 1
They are placeholders for the variables, see example below.
string name = "Malachi";
int age = 24;
Console.WriteLine("My name is {0}, and my age is {1}.", name, age);
This will result in; My name is Malachi, and my age is 24.
{0} is replaced with the variable called "name" {1} is replaced with the variable called "age".
Hope this helps!
0
thank you Tamra