Information Technology Reference
In-Depth Information
WriteLine
WriteLine is another member of Console ; it performs the same functions as Write , but appends
a newline character to the end of each output string.
For example, if you use the preceding code, but use WriteLine instead of Write , the output
is on separate lines:
System.Console.WriteLine("This is text 1.");
System.Console.WriteLine("This is text 2.");
System.Console.WriteLine("This is text 3.");
This code produces the following output in the console window:
This is text 1.
This is text 2.
This is text 3.
The Format String
The general form of the Write and WriteLine statements takes more than a single parameter.
￿
If there is more than a single parameter, the parameters are separated by commas.
￿
The first parameter must always be a string, and is called the format string .
￿
The parameters following the format string are called substitution values . The substitu-
tion values are numbered, starting at 0.
The syntax is as follows:
Console.WriteLine( FormatString , SubVal0 , SubVal1 , SubVal2 , ... );
For example, the following statement has two substitution values, numbered 0 and 1 .
Their values are 3 and 6 , respectively.
Console.WriteLine( "Two sample integers are {0} and {1}." , 3, 6 );
Format string Substitution values
Search WWH ::




Custom Search