TextWriter.Write
TextWriter.Write
TextWriter.Write
TextWriter.Write
Method
Definition
Writes data to a text string or stream.
Overloads
Write(String, Object, Object, Object) Write(String, Object, Object, Object) Write(String, Object, Object, Object) Write(String, Object, Object, Object) |
Writes a formatted string to the text string or stream, using the same semantics as the Format(String, Object, Object, Object) method. |
Write(Char[], Int32, Int32) Write(Char[], Int32, Int32) Write(Char[], Int32, Int32) Write(Char[], Int32, Int32) |
Writes a subarray of characters to the text string or stream. |
Write(String, Object[]) Write(String, Object[]) Write(String, Object[]) Write(String, Object[]) |
Writes a formatted string to the text string or stream, using the same semantics as the Format(String, Object[]) method. |
Write(String, Object) Write(String, Object) Write(String, Object) Write(String, Object) |
Writes a formatted string to the text string or stream, using the same semantics as the Format(String, Object) method. |
Write(UInt64) Write(UInt64) Write(UInt64) Write(UInt64) |
Writes the text representation of an 8-byte unsigned integer to the text string or stream. |
Write(UInt32) Write(UInt32) Write(UInt32) Write(UInt32) |
Writes the text representation of a 4-byte unsigned integer to the text string or stream. |
Write(String) Write(String) Write(String) Write(String) |
Writes a string to the text string or stream. |
Write(Single) Write(Single) Write(Single) Write(Single) |
Writes the text representation of a 4-byte floating-point value to the text string or stream. |
Write(ReadOnlySpan<Char>) Write(ReadOnlySpan<Char>) Write(ReadOnlySpan<Char>) Write(ReadOnlySpan<Char>) | |
Write(String, Object, Object) Write(String, Object, Object) Write(String, Object, Object) Write(String, Object, Object) |
Writes a formatted string to the text string or stream, using the same semantics as the Format(String, Object, Object) method. |
Write(Int64) Write(Int64) Write(Int64) Write(Int64) |
Writes the text representation of an 8-byte signed integer to the text string or stream. |
Write(Int32) Write(Int32) Write(Int32) Write(Int32) |
Writes the text representation of a 4-byte signed integer to the text string or stream. |
Write(Double) Write(Double) Write(Double) Write(Double) |
Writes the text representation of an 8-byte floating-point value to the text string or stream. |
Write(Decimal) Write(Decimal) Write(Decimal) Write(Decimal) |
Writes the text representation of a decimal value to the text string or stream. |
Write(Char[]) Write(Char[]) Write(Char[]) Write(Char[]) |
Writes a character array to the text string or stream. |
Write(Char) Write(Char) Write(Char) Write(Char) |
Writes a character to the text string or stream. |
Write(Boolean) Write(Boolean) Write(Boolean) Write(Boolean) |
Writes the text representation of a |
Write(Object) Write(Object) Write(Object) Write(Object) |
Writes the text representation of an object to the text string or stream by calling the |
Write(String, Object, Object, Object) Write(String, Object, Object, Object) Write(String, Object, Object, Object) Write(String, Object, Object, Object)
Writes a formatted string to the text string or stream, using the same semantics as the Format(String, Object, Object, Object) method.
public:
virtual void Write(System::String ^ format, System::Object ^ arg0, System::Object ^ arg1, System::Object ^ arg2);
public virtual void Write (string format, object arg0, object arg1, object arg2);
abstract member Write : string * obj * obj * obj -> unit
override this.Write : string * obj * obj * obj -> unit
Public Overridable Sub Write (format As String, arg0 As Object, arg1 As Object, arg2 As Object)
Parameters
Exceptions
format
is null
.
The TextWriter is closed.
An I/O error occurs.
format
is not a valid composite format string.
-or-
The index of a format item is less than 0 (zero), or greater than or equal to the number of objects to be formatted (which, for this method overload, is three).
Remarks
This method uses composite formatting to convert the value of an object to its string representation and to embed that representation in a string. .NET 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 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.
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.
Element | Description |
---|---|
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 three objects in its parameter list, the value of index must always be 0, 1, or 2. 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(string 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.
- See also
Write(Char[], Int32, Int32) Write(Char[], Int32, Int32) Write(Char[], Int32, Int32) Write(Char[], Int32, Int32)
Writes a subarray of characters to the text string or stream.
public:
virtual void Write(cli::array <char> ^ buffer, int index, int count);
public virtual void Write (char[] buffer, int index, int count);
abstract member Write : char[] * int * int -> unit
override this.Write : char[] * int * int -> unit
Public Overridable Sub Write (buffer As Char(), index As Integer, count As Integer)
Parameters
- buffer
- Char[]
The character array to write data from.
The character position in the buffer at which to start retrieving data.
Exceptions
The buffer length minus index
is less than count
.
The buffer
parameter is null
.
index
or count
is negative.
The TextWriter is closed.
An I/O error occurs.
Remarks
This method will write count
characters of data into this TextWriter
from the buffer
character array starting at position index
.
This overload is equivalent to the Write(Char[]) overload for each character in buffer
between index
and (index
+ count
).
For a list of common I/O tasks, see Common I/O Tasks.
- See also
Write(String, Object[]) Write(String, Object[]) Write(String, Object[]) Write(String, Object[])
Writes a formatted string to the text string or stream, using the same semantics as the Format(String, Object[]) method.
public:
virtual void Write(System::String ^ format, ... cli::array <System::Object ^> ^ arg);
public virtual void Write (string format, params object[] arg);
abstract member Write : string * obj[] -> unit
override this.Write : string * obj[] -> unit
Public Overridable Sub Write (format As String, ParamArray arg As Object())
Parameters
- arg
- Object[]
An object array that contains zero or more objects to format and write.
Exceptions
format
or arg
is null
.
The TextWriter is closed.
An I/O error occurs.
format
is not a valid composite format string.
-or-
The index of a format item is less than 0 (zero), or greater than or equal to the length of the arg
array.
Remarks
This method uses composite formatting to convert the value of an object to its string representation and to embed that representation in a string. .NET 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 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.
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.
Element | Description |
---|---|
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(string 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.
- See also
Write(String, Object) Write(String, Object) Write(String, Object) Write(String, Object)
Writes a formatted string to the text string or stream, using the same semantics as the Format(String, Object) method.
public:
virtual void Write(System::String ^ format, System::Object ^ arg0);
public virtual void Write (string format, object arg0);
abstract member Write : string * obj -> unit
override this.Write : string * obj -> unit
Public Overridable Sub Write (format As String, arg0 As Object)
Parameters
Exceptions
format
is null
.
The TextWriter is closed.
An I/O error occurs.
format
is not a valid composite format string.
-or-
The index of a format item is less than 0 (zero), or greater than or equal to the number of objects to be formatted (which, for this method overload, is one).
Remarks
This method uses composite formatting to convert the value of an object to its string representation and to embed that representation in a string. .NET 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 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.
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.
Element | Description |
---|---|
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 only a single object in its parameter list, the value of index must always be 0. 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(string 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.
- See also
Write(UInt64) Write(UInt64) Write(UInt64) Write(UInt64)
Important
This API is not CLS-compliant.
Writes the text representation of an 8-byte unsigned integer to the text string or stream.
public:
virtual void Write(System::UInt64 value);
[System.CLSCompliant(false)]
public virtual void Write (ulong value);
abstract member Write : uint64 -> unit
override this.Write : uint64 -> unit
Public Overridable Sub Write (value As ULong)
Parameters
Exceptions
The TextWriter is closed.
An I/O error occurs.
Remarks
The text representation of the specified value is produced by calling the UInt64.ToString method. The TextWriter.FormatProvider property, if not null
, specifies the culture-specific formatting.
For a list of common I/O tasks, see Common I/O Tasks.
- See also
Write(UInt32) Write(UInt32) Write(UInt32) Write(UInt32)
Important
This API is not CLS-compliant.
Writes the text representation of a 4-byte unsigned integer to the text string or stream.
public:
virtual void Write(System::UInt32 value);
[System.CLSCompliant(false)]
public virtual void Write (uint value);
abstract member Write : uint32 -> unit
override this.Write : uint32 -> unit
Public Overridable Sub Write (value As UInteger)
Parameters
Exceptions
The TextWriter is closed.
An I/O error occurs.
Remarks
The text representation of the specified value is produced by calling the UInt32.ToString method. The TextWriter.FormatProvider property, if not null
, specifies the culture-specific formatting.
For a list of common I/O tasks, see Common I/O Tasks.
- See also
Write(String) Write(String) Write(String) Write(String)
Writes a string to the text string or stream.
public:
virtual void Write(System::String ^ value);
public virtual void Write (string value);
abstract member Write : string -> unit
override this.Write : string -> unit
Public Overridable Sub Write (value As String)
Parameters
Exceptions
The TextWriter is closed.
An I/O error occurs.
Remarks
This overload is equivalent to the Write(Char[]) overload.
This method does not search the specified string for individual newline characters (hexadecimal 0x000a) and replace them with TextWriter.NewLine.
If value
is null
, nothing is written to the text stream.
For a list of common I/O tasks, see Common I/O Tasks.
- See also
Write(Single) Write(Single) Write(Single) Write(Single)
Writes the text representation of a 4-byte floating-point value to the text string or stream.
public:
virtual void Write(float value);
public virtual void Write (float value);
abstract member Write : single -> unit
override this.Write : single -> unit
Public Overridable Sub Write (value As Single)
Parameters
Exceptions
The TextWriter is closed.
An I/O error occurs.
Remarks
The text representation of the specified value is produced by calling the Single.ToString method. The TextWriter.FormatProvider property, if not null
, specifies the culture-specific formatting.
For a list of common I/O tasks, see Common I/O Tasks.
- See also
Write(ReadOnlySpan<Char>) Write(ReadOnlySpan<Char>) Write(ReadOnlySpan<Char>) Write(ReadOnlySpan<Char>)
public:
virtual void Write(ReadOnlySpan<char> buffer);
public virtual void Write (ReadOnlySpan<char> buffer);
abstract member Write : ReadOnlySpan<char> -> unit
override this.Write : ReadOnlySpan<char> -> unit
Public Overridable Sub Write (buffer As ReadOnlySpan(Of Char))
Parameters
- buffer
- ReadOnlySpan<Char>
Write(String, Object, Object) Write(String, Object, Object) Write(String, Object, Object) Write(String, Object, Object)
Writes a formatted string to the text string or stream, using the same semantics as the Format(String, Object, Object) method.
public:
virtual void Write(System::String ^ format, System::Object ^ arg0, System::Object ^ arg1);
public virtual void Write (string format, object arg0, object arg1);
abstract member Write : string * obj * obj -> unit
override this.Write : string * obj * obj -> unit
Public Overridable Sub Write (format As String, arg0 As Object, arg1 As Object)
Parameters
Exceptions
format
is null
.
The TextWriter is closed.
An I/O error occurs.
format
is not a valid composite format string.
-or-
The index of a format item is less than 0 (zero) or greater than or equal to the number of objects to be formatted (which, for this method overload, is two).
Remarks
This method uses composite formatting to convert the value of an object to its string representation and to embed that representation in a string. .NET 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 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.
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.
Element | Description |
---|---|
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(string 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.
- See also
Write(Int64) Write(Int64) Write(Int64) Write(Int64)
Writes the text representation of an 8-byte signed integer to the text string or stream.
public:
virtual void Write(long value);
public virtual void Write (long value);
abstract member Write : int64 -> unit
override this.Write : int64 -> unit
Public Overridable Sub Write (value As Long)
Parameters
Exceptions
The TextWriter is closed.
An I/O error occurs.
Remarks
The text representation of the specified value is produced by calling the Int64.ToString method. The TextWriter.FormatProvider property, if not null
, specifies the culture-specific formatting.
For a list of common I/O tasks, see Common I/O Tasks.
- See also
Write(Int32) Write(Int32) Write(Int32) Write(Int32)
Writes the text representation of a 4-byte signed integer to the text string or stream.
public:
virtual void Write(int value);
public virtual void Write (int value);
abstract member Write : int -> unit
override this.Write : int -> unit
Public Overridable Sub Write (value As Integer)
Parameters
Exceptions
The TextWriter is closed.
An I/O error occurs.
Remarks
The text representation of the specified value is produced by calling the Int32.ToString method. The TextWriter.FormatProvider property, if not null
, specifies the culture-specific formatting.
For a list of common I/O tasks, see Common I/O Tasks.
- See also
Write(Double) Write(Double) Write(Double) Write(Double)
Writes the text representation of an 8-byte floating-point value to the text string or stream.
public:
virtual void Write(double value);
public virtual void Write (double value);
abstract member Write : double -> unit
override this.Write : double -> unit
Public Overridable Sub Write (value As Double)
Parameters
Exceptions
The TextWriter is closed.
An I/O error occurs.
Remarks
The text representation of the specified value is produced by calling the Double.ToString method. The TextWriter.FormatProvider property, if not null
, specifies the culture-specific formatting.
For a list of common I/O tasks, see Common I/O Tasks.
- See also
Write(Decimal) Write(Decimal) Write(Decimal) Write(Decimal)
Writes the text representation of a decimal value to the text string or stream.
public:
virtual void Write(System::Decimal value);
public virtual void Write (decimal value);
abstract member Write : decimal -> unit
override this.Write : decimal -> unit
Public Overridable Sub Write (value As Decimal)
Parameters
Exceptions
The TextWriter is closed.
An I/O error occurs.
Remarks
The FormatProvider property, if not null
, specifies the culture-specific formatting.
- See also
Write(Char[]) Write(Char[]) Write(Char[]) Write(Char[])
Writes a character array to the text string or stream.
public:
virtual void Write(cli::array <char> ^ buffer);
public virtual void Write (char[] buffer);
abstract member Write : char[] -> unit
override this.Write : char[] -> unit
Public Overridable Sub Write (buffer As Char())
Parameters
- buffer
- Char[]
The character array to write to the text stream.
Exceptions
The TextWriter is closed.
An I/O error occurs.
Remarks
This method does not search the specified string for individual newline characters (hexadecimal 0x000a) and replace them with NewLine.
This default method calls the Write(Char[], Int32, Int32) method and passes the entire character array. If the character array is null
, nothing is written.
For a list of common I/O tasks, see Common I/O Tasks.
- See also
Write(Char) Write(Char) Write(Char) Write(Char)
Writes a character to the text string or stream.
public:
virtual void Write(char value);
public virtual void Write (char value);
abstract member Write : char -> unit
override this.Write : char -> unit
Public Overridable Sub Write (value As Char)
Parameters
Exceptions
The TextWriter is closed.
An I/O error occurs.
Remarks
This default method does nothing, but derived classes can override the method to provide the appropriate functionality.
For a list of common I/O tasks, see Common I/O Tasks.
- See also
Write(Boolean) Write(Boolean) Write(Boolean) Write(Boolean)
Writes the text representation of a Boolean
value to the text string or stream.
public:
virtual void Write(bool value);
public virtual void Write (bool value);
abstract member Write : bool -> unit
override this.Write : bool -> unit
Public Overridable Sub Write (value As Boolean)
Parameters
Exceptions
The TextWriter is closed.
An I/O error occurs.
Remarks
The text representation of the specified value is produced by calling the Boolean.ToString method.
This method outputs either Boolean.TrueString or Boolean.FalseString.
For a list of common I/O tasks, see Common I/O Tasks.
- See also
Write(Object) Write(Object) Write(Object) Write(Object)
Writes the text representation of an object to the text string or stream by calling the ToString
method on that object.
public:
virtual void Write(System::Object ^ value);
public virtual void Write (object value);
abstract member Write : obj -> unit
override this.Write : obj -> unit
Public Overridable Sub Write (value As Object)
Parameters
Exceptions
The TextWriter is closed.
An I/O error occurs.
Remarks
This overload is equivalent to the Write(String) overload.
If the specified object is null
, no action is taken and no exception is thrown. Otherwise, the object's ToString
method is called to produce the string representation, and the resulting string is then written to the output stream. The FormatProvider property, if not null
, specifies the culture-specific formatting.
For a list of common I/O tasks, see Common I/O Tasks.
- See also
Applies to
Feedback
We'd love to hear your thoughts. Choose the type you'd like to provide:
Our feedback system is built on GitHub Issues. Read more on our blog.
Loading feedback...