StringWriter Class

Implements a TextWriter for writing information to a string. The information is stored in an underlying StringBuilder.

Syntax

Declaration

[Serializable]
[ComVisible(true)]
public class StringWriter : TextWriter, IDisposable

Inheritance Hierarchy

Constructors summary

Initializes a new instance of the StringWriter class.

Initializes a new instance of the StringWriter class with the specified format control.

Initializes a new instance of the StringWriter class that writes to the specified StringBuilder.

Initializes a new instance of the StringWriter class that writes to the specified StringBuilder and has the specified format provider.

Properties summary

Gets the Encoding in which the output is written.

Methods summary

Releases the unmanaged resources used by the StringWriter and optionally releases the managed resources.

Asynchronously clears all buffers for the current writer and causes any buffered data to be written to the underlying device.

Returns the underlying StringBuilder.

Returns a string containing the characters written to the current StringWriter so far.

Writes a character to the string.

Writes a subarray of characters to the string.

Writes a string to the current string.

Writes a character to the string asynchronously.

Writes a subarray of characters to the string asynchronously.

Writes a string to the current string asynchronously.

Writes a character followed by a line terminator asynchronously to the string.

Writes a subarray of characters followed by a line terminator asynchronously to the string.

Writes a string followed by a line terminator asynchronously to the current string.

Constructors

Properties

  • Encoding

    Gets the Encoding in which the output is written.

    public override Encoding Encoding { get; }

    Property Value

    • The Encoding in which the output is written.

    Overrides

Methods

  • Dispose(Boolean)

    Releases the unmanaged resources used by the StringWriter and optionally releases the managed resources.

    protected override void Dispose(bool disposing)

    Parameters

    • disposing

      true to release both managed and unmanaged resources; false to release only unmanaged resources.

    Overrides

  • FlushAsync()

    Asynchronously clears all buffers for the current writer and causes any buffered data to be written to the underlying device.

    [HostProtection(ExternalThreading = true)]
    [ComVisible(false)]
    public override Task FlushAsync()

    Returns

    • A task that represents the asynchronous flush operation.

    Overrides

  • GetStringBuilder()

    Returns the underlying StringBuilder.

    public virtual StringBuilder GetStringBuilder()

    Returns

  • ToString()

    Returns a string containing the characters written to the current StringWriter so far.

    public override string ToString()

    Returns

    • The string containing the characters written to the current StringWriter.

    Overrides

  • Write(Char)

    Writes a character to the string.

    public override void Write(char value)

    Parameters

    • value

      The character to write.

    Exceptions

    Overrides

  • Write(Char[], Int32, Int32)

    Writes a subarray of characters to the string.

    public override void Write(char[] buffer, int index, int count)

    Parameters

    • buffer

      The character array to write data from.

    • index

      The position in the buffer at which to start reading data.

    • count

      The maximum number of characters to write.

    Exceptions

    Overrides

  • Write(String)

    Writes a string to the current string.

    public override void Write(string value)

    Parameters

    • value

      The string to write.

    Exceptions

    Overrides

  • WriteAsync(Char)

    Writes a character to the string asynchronously.

    [HostProtection(ExternalThreading = true)]
    [ComVisible(false)]
    public override Task WriteAsync(char value)

    Parameters

    • value

      The character to write to the string.

    Returns

    • A task that represents the asynchronous write operation.

    Exceptions

    Overrides

  • WriteAsync(Char[], Int32, Int32)

    Writes a subarray of characters to the string asynchronously.

    [HostProtection(ExternalThreading = true)]
    [ComVisible(false)]
    public override Task WriteAsync(char[] buffer, int index, int count)

    Parameters

    • buffer

      The character array to write data from.

    • index

      The position in the buffer at which to start reading data.

    • count

      The maximum number of characters to write.

    Returns

    • A task that represents the asynchronous write operation.

    Exceptions

    Overrides

  • WriteAsync(String)

    Writes a string to the current string asynchronously.

    [HostProtection(ExternalThreading = true)]
    [ComVisible(false)]
    public override Task WriteAsync(string value)

    Parameters

    • value

      The string to write. If value is null, nothing is written to the text stream.

    Returns

    • A task that represents the asynchronous write operation.

    Exceptions

    Overrides

  • WriteLineAsync(Char)

    Writes a character followed by a line terminator asynchronously to the string.

    [HostProtection(ExternalThreading = true)]
    [ComVisible(false)]
    public override Task WriteLineAsync(char value)

    Parameters

    • value

      The character to write to the string.

    Returns

    • A task that represents the asynchronous write operation.

    Exceptions

    Overrides

  • WriteLineAsync(Char[], Int32, Int32)

    Writes a subarray of characters followed by a line terminator asynchronously to the string.

    [HostProtection(ExternalThreading = true)]
    [ComVisible(false)]
    public override Task WriteLineAsync(char[] buffer, int index, int count)

    Parameters

    • buffer

      The character array to write data from.

    • index

      The position in the buffer at which to start reading data.

    • count

      The maximum number of characters to write.

    Returns

    • A task that represents the asynchronous write operation.

    Exceptions

    Overrides

  • WriteLineAsync(String)

    Writes a string followed by a line terminator asynchronously to the current string.

    [HostProtection(ExternalThreading = true)]
    [ComVisible(false)]
    public override Task WriteLineAsync(string value)

    Parameters

    • value

      The string to write. If the value is null, only a line terminator is written.

    Returns

    • A task that represents the asynchronous write operation.

    Exceptions

    Overrides

Details

Namespace

System.IO

Assembly

System.IO.dll

See Also