+ 1

Why for print the value of variable is necessary "... {0}..."?

sorry for my English

12th May 2017, 10:25 AM
Lucas
2 Answers
+ 1
It isn't necessary, it's just one of the ways of doing it. I assume you're talking about Console.WriteLine? In the following code: string x = "This"; string y = "is"; string z = "an"; Console.WriteLine("{0} {1} {2} example", x, y, z); The output will be "This is an example", because {0} refers to the first given variable (x), {1} to the second one (y) and {2} to the third one (z). But another way of doing the same thing would be: Console.WriteLine(x + " " + y + " " + z + " example");
12th May 2017, 5:18 PM
Oni
0
Or, in case you are wondering why 0 (instead of 1), such things are generally counted starting from 0 in C#. You'll see the same thing happening when you study arrays.
12th May 2017, 5:25 PM
Oni