Information Technology Reference
In-Depth Information
Substituting Values
Substitution values are used to display the values of program data and variables. To use them,
do the following:
Place these values or variables as substitution values, after the format string.
Include
substitution markers
in the format string.
A substitution marker marks the position in the format string where a value should be sub-
stituted in the output string. It consists of an integer enclosed in a set of matching curly braces.
The integer is the numeric position of the substitution value to be used.
There are two things to note in the following example:
The format string of this
WriteLine
statement includes two substitution markers and two
integer substitution values.
When the statement is executed, the substitution markers are replaced by the substitu-
tion values in the output string.
Substitution markers
↓
↓
Console.WriteLine(
"Two sample integers are {0} and {1}."
,
3, 6
);
↑
↑
Format string
Substitution values
This code displays the following on the screen:
Two sample integers are 3 and 6.