- 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); }
5 Réponses
+ 2
{0} and {1} are replaced with x and y variables accordingly in the string.
+ 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.
+ 1
this is how you format a string every language has a certain way.. in C you do it like "x = %d ", x
+ 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.
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.