+ 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); } } }
5 odpowiedzi
+ 12
See SoloLearn's C# course at 'Basic concepts', 'Printing text', lesson 2.
+ 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).
+ 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.
+ 2
Thank you so much!
+ 1
That's why i came here,it doesn't explain what a formatted string means