Write Method (String, Object[])

TextWriter.Write Method (String, Object[])


Writes a formatted string to the text string or stream, using the same semantics as the String.Format(String, Object[]) method.

Namespace:   System.IO
Assembly:  mscorlib (in mscorlib.dll)

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


Type: System.String

A composite format string (see Remarks).

Type: System.Object[]

An object array that contains zero or more objects to format and write.

Exception Condition

format or arg is null.


The TextWriter is closed.


An I/O error occurs.


format is not a valid composite format string.


The index of a format item is less than 0 (zero), or greater than or equal to the length of the arg array.

This method uses the 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:


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.




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.


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.


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 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.

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

Universal Windows Platform
Available since 4.5
.NET Framework
Available since 1.1
Portable Class Library
Supported in: portable .NET platforms
Available since 2.0
Windows Phone Silverlight
Available since 7.0
Windows Phone
Available since 8.1
Return to top
© 2015 Microsoft