Console::Write Method (String^, array<Object^>^)
Writes the text representation of the specified array of objects to the standard output stream using the specified format information.
Assembly: mscorlib (in mscorlib.dll)
public: [HostProtectionAttribute(SecurityAction::LinkDemand, UI = true)] static void Write( String^ format, ... array<Object^>^ arg )
Parameters
- format
-
Type:
System::String^
A composite format string (see Remarks).
- arg
-
Type:
array<System::Object^>^
An array of objects to write using format.
| Exception | Condition |
|---|---|
| IOException | An I/O error occurred. |
| ArgumentNullException | format or arg is null. |
| FormatException | 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.
For more information about the composite formatting feature supported by methods such as Format, AppendFormat, and some overloads of WriteLine, 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 Date and Time Format Strings and Custom Date and Time Format Strings.
For more information about enumeration format specifiers, see Enumeration Format Strings.
For more information about formatting, see Formatting Types in the .NET Framework.
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.
for modifying safe top-level windows and subwindows. Associated enumeration: UIPermissionWindow::SafeTopLevelWindows
Available since 1.1
Silverlight
Available since 2.0
Windows Phone Silverlight
Available since 7.0
Note that the example calls the Write(String^, array<Object^>^) method rather than the WriteLine(String^, array<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.