0

I don't get it

static void Main(string[] args) { int x = 10; double y = 20; Console.WriteLine("x = {0}; y = {1}", x, y); } // Output: x = 10; y = 20 I dont get the inside of writeline I tried Console.Writeline(x, y); but i got an error: Argument 1: cannot convert from 'int' to 'string' And I thought output shows between " " exact same. Can you explain how that works? Thanks in advance.

22nd Aug 2017, 8:10 PM
Hamza Sevencan
Hamza Sevencan - avatar
3 Réponses
+ 6
See the {0} and {1} as place holders. Let's say this: Console.WriteLine("{0} + {1} = {2}",1,1,2); That basically mean that in the place of {0} there will be a 1, it's the first argument after the Formatting​ String (It's the "{0} + {1} = {2}" string) Let's take this: Console.WriteLine("{0} + {1} = {2}", 1, 1, 2); {0} = 1 {1} = 1 {2} = 2 Then it's almost like: Console.WriteLine("1 + 1 = 2"); I hope this helps
22nd Aug 2017, 8:29 PM
Limitless
Limitless - avatar
+ 1
Yes i finally got it! Much thanks
22nd Aug 2017, 8:32 PM
Hamza Sevencan
Hamza Sevencan - avatar