Writes a formatted string and a new line to the text string or stream, using the same semantics as the string.Format(string, object, object) method.
Type Reason ArgumentNullException format is null. System.IO.IOException An 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 the number of provided objects to be formatted (2).
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:
For more information about the composite formatting feature, see Composite Formatting.
For more information about numeric format specifiers, see Standard Numeric Format Strings and Custom Numeric Format Strings.
For more information about date and time format specifiers, see Standard DateTime Format Strings and Custom DateTime Format Strings.
For more information about enumeration format specifiers, see Enumeration Format Strings.
For more information about formatting, see Formatting Types.
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 two objects in its parameter list, the value of index must always be 0 or 1. 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.