What is formatting and what is it used for? | Sololearn: Learn to code for FREE!
New course! Every coder should learn Generative AI!
Try a free lesson
+ 1

What is formatting and what is it used for?

K so I'm a newbie and I'm on the first lessons: https://www.sololearn.com/learn/CSharp/2584/ I don't get the displaying a formatted string thing. What is it used for? Why does it replace the {0} and {1}? Why do we write them then if they're not used? Isn't it the same to just write a value for x and y, and then print them? Please explain. Thank you in advance.

1st Jun 2019, 9:22 PM
juan juanov
juan juanov - avatar
3 Answers
+ 3
The numbers inside the {} do matter for giving the order of the sequence, {1} {0} will print the string that supposed to be formatted but in reverse as the {1} came before the {0}
1st Jun 2019, 9:26 PM
Mo Hani
Mo Hani - avatar
+ 3
Great, thanks a lot, I got it pretty fast after reading you both and experimenting a bit!
1st Jun 2019, 9:41 PM
juan juanov
juan juanov - avatar
+ 3
BTW at the time a program runs, the values that variables have is not necessarily known by the programmer which is why a programmer can't write the exact values in an output statement.
2nd Jun 2019, 12:51 AM
Sonic
Sonic - avatar