- 1

What does string part do in console.writeline method and why we assign 0 to x and 1 to y?

static void Main(string[] args) { int x = 10; double y = 20; Console.WriteLine("x = {0}; y = {1}", x, y); }

3rd Sep 2016, 10:15 AM
Vivek Vishwakarma
Vivek Vishwakarma - avatar
5 Réponses
+ 2
{0} and {1} are replaced with x and y variables accordingly in the string.
3rd Sep 2016, 10:48 AM
SergeiRom
+ 2
the string part is what it will print out for you as answer, the 0 means the first element after the " marks, the 1 means the second, works similar to index. Excuse my simple english.
3rd Sep 2016, 11:40 AM
Benedek Máté Tóth
Benedek Máté Tóth - avatar
+ 1
this is how you format a string every language has a certain way.. in C you do it like "x = %d ", x
3rd Sep 2016, 11:10 PM
Ilyes Bouchada
Ilyes Bouchada - avatar
+ 1
Think of the {0} and {1} as place holders for your variables that allow you to format the output string to look the way you want it to.
4th Sep 2016, 4:07 AM
sean
0
string part will print or hold variable values which you assign as x and y.Also you can use 1 for x or 0 for y there is no such criteria.
4th Sep 2016, 7:36 AM
Manik Kore
Manik Kore - avatar