Click here to Skip to main content
15,890,282 members
Please Sign up or sign in to vote.
1.00/5 (3 votes)
See more:
C#
Console.WriteLine("{0,2} + {1,2} = {2,2}\t{3,2} * {4,2} = {5,4}",
                             i, 100 - i, i + (100 - i),
                             i, 100 - i, i * (100 - i));
Posted
Updated 23-Jun-15 21:10pm
v3

It's a simple output-to-the-console instruction. It outputs 5 values in the form:
nn + nn = nn      nn * nn = nn

The first parameter (the string) specifies the way the data will be presented, the remaining ones provide the values to show.
Each item in curly brackets in the format string handles a single one of the value parameters: so {0,2} says "insert the first value parameter", {1,2} says "insert the second value parameter" and so forth.
Within the curly brackets, the first number refers to the value parameter index: 0 for the first, 1 for the second, and so forth.
The comma and the second number is optional, and specifies a formatted size for the value: in this case "2" which means that each value will be a minimum of two characters long when printed, so a value of 7 will occupy the same space on screen as a value of 27.
The \t is a "special character" which provides some space between the two parts of the output.
 
Share this answer
 
I was wondering what {0,2} meant. Now I realize that the '2' is included just to specify spacing.

C#
Console.WriteLine("{0} + {1} = {2}\t{3} * {4} = {5}",
                             i, 100 - i, i + (100 - i),
                             i, 100 - i, i * (100 - i));




This code would give same results....but with the default spacing.
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

  Print Answers RSS


CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900