+ 1

What does a formatted string means? And what is it's function?

using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks; namespace SoloLearn { class Program { static void Main(string[] args) { int x = 10; double y = 20; Console.WriteLine("x = {0}; y = {1}", x, y); } } }

13th Mar 2017, 5:17 PM
peshang
peshang - avatar
5 odpowiedzi
+ 12
See SoloLearn's C# course at 'Basic concepts', 'Printing text', lesson 2.
13th Mar 2017, 6:32 PM
Tashi N
Tashi N - avatar
+ 11
When you output a string with Console, you can replace placeholders by variable value to format your string. In your example {0} will be replaced by the value of the first variable after ',' (your variable is x, value of x is 10 - {0} will be replaced by 10). {1} will be replaced by the value of the second variable (your second variable is y, value of y is 20 - {1} will be replaced by 20).
13th Mar 2017, 6:51 PM
Tashi N
Tashi N - avatar
+ 2
not sure about c#, but in java they have a printf function System.out.printf("put a number here: %d",x); where x is an integer. it will take the parameters and fill them in left to right in the string argument. i assume it works the same way, just not sure the exact way.
13th Mar 2017, 5:55 PM
Michael Szczepanski
Michael Szczepanski - avatar
+ 2
Thank you so much!
13th Mar 2017, 7:09 PM
peshang
peshang - avatar
+ 1
That's why i came here,it doesn't explain what a formatted string means
13th Mar 2017, 6:46 PM
peshang
peshang - avatar