System.IO.TextWriter.WriteLine Method

Writes out a formatted string and a new line, using the same semantics as string.Format(string, object).

Syntax

public virtual void WriteLine (string format, params object[] arg)

Parameters

format
A composite format string (see Remarks).
arg
An object array that contains zero or more objects to format and write.

Exceptions

TypeReason
ArgumentNullException format or arg is null.
System.IO.IOExceptionAn I/O error occurred.
FormatException

The format specification in format is invalid.

-or-

The number indicating an argument to be formatted is less than zero, or greater than or equal to arg.Length.

Remarks

This method uses the composite formatting feature of the .NET Framework to convert the value of an object to its string representation and to embed that representation in a string. The .NET Framework provides extensive formatting support, which is described in greater detail in the following formatting topics:

The format parameter consists of zero or more runs of text intermixed with zero or more indexed placeholders, called format items, that correspond to an object in the parameter list of this method. The formatting process replaces each format item with the string representation of the value of the corresponding object.

The syntax of a format item is as follows:

{index[,length][:formatString]}

Elements in square brackets are optional. The following table describes each element. For more information about the composite formatting feature, including the syntax of a format item, see Composite Formatting.

index

The zero-based position in the parameter list of the object to be formatted. If the object specified by index is null, the format item is replaced by string.Empty. Because this overload has an array in its parameter list, the value of index must always be less than the length of the array. If there is no parameter in the index position, a FormatException is thrown.

,length

The minimum number of characters in the string representation of the parameter. If positive, the parameter is right-aligned; if negative, it is left-aligned.

:formatString

A standard or custom format string that is supported by the object to be formatted. Possible values for formatString are the same as the values supported by the object's ToString(format) method. If formatString is not specified and the object to be formatted implements the IFormattable interface, null is passed as the value of the format parameter that is used as the IFormattable.ToString(string, IFormatProvider) format string.

The leading and trailing brace characters, "{" and "}", are required. To specify a single literal brace character in format, specify two leading or trailing brace characters; that is, "{{" or "}}".

This method does not search the specified string for individual newline characters (hexadecimal 0x000a) and replace them with TextWriter.NewLine.

If a specified object is not referenced in the format string, it is ignored.

The line terminator is defined by the TextWriter.CoreNewLine field.

For a list of common I/O tasks, see Common I/O Tasks.

Requirements

Namespace: System.IO
Assembly: mscorlib (in mscorlib.dll)
Assembly Versions: 1.0.5000.0, 2.0.0.0, 4.0.0.0