Console.Write Method (String, Object[])


The .NET API Reference documentation has a new home. Visit the .NET API Browser on to see the new experience.

Writes the text representation of the specified array of objects to the standard output stream using the specified format information.

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

[<HostProtectionAttribute(SecurityAction.LinkDemand, UI = true)>]
static member Write : 
        format:string *
        [<ParamArrayAttribute>] arg:Object[] -> unit


Type: System.String

A composite format string (see Remarks).

Type: System.Object[]

An array of objects to write using format.

Exception Condition

An I/O error occurred.


format or arg is null.


The format specification in format is invalid.

This method uses the composite formatting feature of the .NET Framework to convert the value of an object to its text representation and embed that representation in a string. The resulting string is written to the output stream.

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 text representation of the value of the corresponding object.

The syntax of a format item is {index[,alignment][:formatString]}, which specifies a mandatory index, the optional length and alignment of the formatted text, and an optional string of format specifier characters that govern how the value of the corresponding object is formatted.

The .NET Framework provides extensive formatting support, which is described in greater detail in the following formatting topics.

The arg parameter is a parameter array. Arguments can be passed to the method either as an array or as list of five or more items. The examples illustrate both forms of method call.

Notes to Callers:

This method is not called by C++ code. The C++ compiler resolves calls to Write that include a string and a list of four or more object parameters as a call to Write(String, Object, Object, Object, Object). It resolves calls to Write that include a string and an object array as a call to Write(String, Object).

The following example defines a Person class with a number of properties that provide information about a person. Its GetDescription method returns an array that contains all of the property values except one. The example then uses the array returned by the GetDescription method to display the values of the Person object.

No code example is currently available or this language may not be supported.

Note that the example calls the Write(String, Object[]) method rather than the WriteLine(String, Object[]) method because it attempts to display the value of the Person.Remarks property on the same line. To do this, it examines the value of the CursorLeft and WindowWidth properties to determine whether there is enough space for the remark to fit. If there is, it displays the line. If not, it writes a line, indents three spaces, and displays the remark.

The following example is identical to the first, except that it supplies a five-item list as the arg argument instead of a parameter array.

No code example is currently available or this language may not be supported.


for modifying safe top-level windows and subwindows. Associated enumeration: UIPermissionWindow.SafeTopLevelWindows

.NET Framework
Available since 1.1
Available since 2.0
Windows Phone Silverlight
Available since 7.0
Return to top