Early Preview

This is currently very much a preview. Please feel free to try things out, but don't be upset if anything is not yet working. Feedback is welcome over on our GitHub Dicussions page.

class System.​IO.​StringWriter

Assembly: System.Runtime

Inheritance: object → MarshalByRefObjectTextWriter → StringWriter

Implements a <see cref="T:System.IO.TextWriter" /> for writing information to a string. The information is stored in an underlying <see cref="T:System.Text.StringBuilder" /> .

Fields and Constants

protected char[]
CoreNewLine
Stores the newline characters used for this <see langword="TextWriter" /> .

Properties

Encoding
Gets the <see cref="T:System.Text.Encoding" /> in which the output is written.
FormatProvider
Gets an object that controls formatting.
public string
NewLine
Gets or sets the line terminator string used by the current <see langword="TextWriter" /> .

Methods

public void
Close​()
Closes the current <see cref="T:System.IO.StringWriter" /> and the underlying stream.
protected void
Dispose​(bool disposing)
disposing <see langword="true" /> to release both managed and unmanaged resources; <see langword="false" /> to release only unmanaged resources.
Releases the unmanaged resources used by the <see cref="T:System.IO.StringWriter" /> and optionally releases the managed resources.
FlushAsync​()
Returns A task that represents the asynchronous flush operation.
Asynchronously clears all buffers for the current writer and causes any buffered data to be written to the underlying device.
GetStringBuilder​()
Returns The underlying <see langword="StringBuilder" /> .
Returns the underlying <see cref="T:System.Text.StringBuilder" /> .
public string
ToString​()
Returns The string containing the characters written to the current <see langword="StringWriter" /> .
Returns a string containing the characters written to the current <see langword="StringWriter" /> so far.
public void
Write​(char value)
value The character to write.
Writes a character to the string.
public void
Write​(char[] buffer, int index, int count)
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.
Writes a subarray of characters to the string.
public void
Write​(ReadOnlySpan`1 buffer)
public void
Write​(string value)
value The string to write.
Writes a string to the current string.
public void
Write​(Text.StringBuilder value)
value The string builder to write to the string.
Writes the string representation of a string builder to the current string.
WriteAsync​(char value)
value The character to write to the string.
Returns A task that represents the asynchronous write operation.
Writes a character to the string asynchronously.
WriteAsync​(char[] buffer, int index, int count)
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.
Writes a subarray of characters to the string asynchronously.
WriteAsync​(ReadOnlyMemory`1 buffer, Threading.CancellationToken cancellationToken = null)
WriteAsync​(string value)
value The string to write. If <paramref name="value" /> is <see langword="null" /> , nothing is written to the text stream.
Returns A task that represents the asynchronous write operation.
Writes a string to the current string asynchronously.
WriteAsync​(Text.StringBuilder value, Threading.CancellationToken cancellationToken = null)
value The string builder to write to the string.
cancellationToken The token to monitor for cancellation requests. The default value is <see cref="P:System.Threading.CancellationToken.None" /> .
Returns A task that represents the asynchronous write operation.
Asynchronously writes the text representation of a string builder to the string.
public void
WriteLine​(ReadOnlySpan`1 buffer)
public void
WriteLine​(Text.StringBuilder value)
value The string, as a string builder, to write to the string.
Writes the text representation of a string builder to the string, followed by a line terminator.
WriteLineAsync​(char value)
value The character to write to the string.
Returns A task that represents the asynchronous write operation.
Asynchronously writes a character to the string, followed by a line terminator.
WriteLineAsync​(char[] buffer, int index, int count)
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.
asynchronously writes a subarray of characters to the string, followed by a line terminator.
WriteLineAsync​(ReadOnlyMemory`1 buffer, Threading.CancellationToken cancellationToken = null)
WriteLineAsync​(string value)
value The string to write. If the value is <see langword="null" /> , only a line terminator is written.
Returns A task that represents the asynchronous write operation.
Asynchronously writes a string to the current string, followed by a line terminator.
WriteLineAsync​(Text.StringBuilder value, Threading.CancellationToken cancellationToken = null)
value The string builder to write to the string.
cancellationToken The token to monitor for cancellation requests. The default value is <see cref="P:System.Threading.CancellationToken.None" /> .
Returns A task that represents the asynchronous write operation.
Asynchronously writes the string representation of the string builder to the current string, followed by a line terminator.
public void
Dispose​()
Inherited from TextWriter
Releases all resources used by the <see cref="T:System.IO.TextWriter" /> object.
DisposeAsync​()
Inherited from TextWriter
Returns A task that represents the asynchronous dispose operation.
Asynchronously releases all resources used by the <see cref="T:System.IO.TextWriter" /> object.
public void
Flush​()
Inherited from TextWriter
Clears all buffers for the current writer and causes any buffered data to be written to the underlying device.
FlushAsync​(Threading.CancellationToken cancellationToken)
Inherited from TextWriter
cancellationToken The <see cref="T:System.Threading.CancellationToken" /> to monitor for cancellation requests.
Returns A <see cref="T:System.Threading.Tasks.Task" /> that represents the asynchronous flush operation.
Asynchronously clears all buffers for the current writer and causes any buffered data to be written to the underlying device.
public void
Write​(bool value)
Inherited from TextWriter
value The <see langword="Boolean" /> value to write.
Writes the text representation of a <see langword="Boolean" /> value to the text stream.
public void
Write​(char[] buffer)
Inherited from TextWriter
buffer The character array to write to the text stream.
Writes a character array to the text stream.
public void
Write​(decimal value)
Inherited from TextWriter
value The decimal value to write.
Writes the text representation of a decimal value to the text stream.
public void
Write​(double value)
Inherited from TextWriter
value The 8-byte floating-point value to write.
Writes the text representation of an 8-byte floating-point value to the text stream.
public void
Write​(int value)
Inherited from TextWriter
value The 4-byte signed integer to write.
Writes the text representation of a 4-byte signed integer to the text stream.
public void
Write​(long value)
Inherited from TextWriter
value The 8-byte signed integer to write.
Writes the text representation of an 8-byte signed integer to the text stream.
public void
Write​(object value)
Inherited from TextWriter
value The object to write.
Writes the text representation of an object to the text stream by calling the <see langword="ToString" /> method on that object.
public void
Write​(Single value)
Inherited from TextWriter
value The 4-byte floating-point value to write.
Writes the text representation of a 4-byte floating-point value to the text stream.
public void
Write​(string format, object arg0)
Inherited from TextWriter
format A composite format string.
arg0 The object to format and write.
Writes a formatted string to the text stream, using the same semantics as the <see cref="M:System.String.Format(System.String,System.Object)" /> method.
public void
Write​(string format, object arg0, object arg1)
Inherited from TextWriter
format A composite format string.
arg0 The first object to format and write.
arg1 The second object to format and write.
Writes a formatted string to the text stream using the same semantics as the <see cref="M:System.String.Format(System.String,System.Object,System.Object)" /> method.
public void
Write​(string format, object arg0, object arg1, object arg2)
Inherited from TextWriter
format A composite format string.
arg0 The first object to format and write.
arg1 The second object to format and write.
arg2 The third object to format and write.
Writes a formatted string to the text stream, using the same semantics as the <see cref="M:System.String.Format(System.String,System.Object,System.Object,System.Object)" /> method.
public void
Write​(string format, object[] arg)
Inherited from TextWriter
format A composite format string.
arg An object array that contains zero or more objects to format and write.
Writes a formatted string to the text stream, using the same semantics as the <see cref="M:System.String.Format(System.String,System.Object[])" /> method.
public void
Write​(string format, ReadOnlySpan`1 arg)
Inherited from TextWriter
public void
Write​(uint value)
Inherited from TextWriter
value The 4-byte unsigned integer to write.
Writes the text representation of a 4-byte unsigned integer to the text stream.
public void
Write​(ulong value)
Inherited from TextWriter
value The 8-byte unsigned integer to write.
Writes the text representation of an 8-byte unsigned integer to the text stream.
WriteAsync​(char[] buffer)
Inherited from TextWriter
buffer The character array to write to the text stream. If <paramref name="buffer" /> is <see langword="null" /> , nothing is written.
Returns A task that represents the asynchronous write operation.
Writes a character array to the text stream asynchronously.
public void
WriteLine​()
Inherited from TextWriter
Writes a line terminator to the text stream.
public void
WriteLine​(bool value)
Inherited from TextWriter
value The <see langword="Boolean" /> value to write.
Writes the text representation of a <see langword="Boolean" /> value to the text stream, followed by a line terminator.
public void
WriteLine​(char value)
Inherited from TextWriter
value The character to write to the text stream.
Writes a character to the text stream, followed by a line terminator.
public void
WriteLine​(char[] buffer)
Inherited from TextWriter
buffer The character array from which data is read.
Writes an array of characters to the text stream, followed by a line terminator.
public void
WriteLine​(char[] buffer, int index, int count)
Inherited from TextWriter
buffer The character array from which data is read.
index The character position in <paramref name="buffer" /> at which to start reading data.
count The maximum number of characters to write.
Writes a subarray of characters to the text stream, followed by a line terminator.
public void
WriteLine​(decimal value)
Inherited from TextWriter
value The decimal value to write.
Writes the text representation of a decimal value to the text stream, followed by a line terminator.
public void
WriteLine​(double value)
Inherited from TextWriter
value The 8-byte floating-point value to write.
Writes the text representation of a 8-byte floating-point value to the text stream, followed by a line terminator.
public void
WriteLine​(int value)
Inherited from TextWriter
value The 4-byte signed integer to write.
Writes the text representation of a 4-byte signed integer to the text stream, followed by a line terminator.
public void
WriteLine​(long value)
Inherited from TextWriter
value The 8-byte signed integer to write.
Writes the text representation of an 8-byte signed integer to the text stream, followed by a line terminator.
public void
WriteLine​(object value)
Inherited from TextWriter
value The object to write. If <paramref name="value" /> is <see langword="null" /> , only the line terminator is written.
Writes the text representation of an object to the text stream, by calling the <see langword="ToString" /> method on that object, followed by a line terminator.
public void
WriteLine​(Single value)
Inherited from TextWriter
value The 4-byte floating-point value to write.
Writes the text representation of a 4-byte floating-point value to the text stream, followed by a line terminator.
public void
WriteLine​(string value)
Inherited from TextWriter
value The string to write. If <paramref name="value" /> is <see langword="null" /> , only the line terminator is written.
Writes a string to the text stream, followed by a line terminator.
public void
WriteLine​(string format, object arg0)
Inherited from TextWriter
format A composite format string.
arg0 The object to format and write.
Writes a formatted string and a new line to the text stream, using the same semantics as the <see cref="M:System.String.Format(System.String,System.Object)" /> method.
public void
WriteLine​(string format, object arg0, object arg1)
Inherited from TextWriter
format A composite format string.
arg0 The first object to format and write.
arg1 The second object to format and write.
Writes a formatted string and a new line to the text stream, using the same semantics as the <see cref="M:System.String.Format(System.String,System.Object,System.Object)" /> method.
public void
WriteLine​(string format, object arg0, object arg1, object arg2)
Inherited from TextWriter
format A composite format string.
arg0 The first object to format and write.
arg1 The second object to format and write.
arg2 The third object to format and write.
Writes out a formatted string and a new line to the text stream, using the same semantics as <see cref="M:System.String.Format(System.String,System.Object)" /> .
public void
WriteLine​(string format, object[] arg)
Inherited from TextWriter
format A composite format string.
arg An object array that contains zero or more objects to format and write.
Writes out a formatted string and a new line to the text stream, using the same semantics as <see cref="M:System.String.Format(System.String,System.Object)" /> .
public void
WriteLine​(string format, ReadOnlySpan`1 arg)
Inherited from TextWriter
public void
WriteLine​(uint value)
Inherited from TextWriter
value The 4-byte unsigned integer to write.
Writes the text representation of a 4-byte unsigned integer to the text stream, followed by a line terminator.
public void
WriteLine​(ulong value)
Inherited from TextWriter
value The 8-byte unsigned integer to write.
Writes the text representation of an 8-byte unsigned integer to the text stream, followed by a line terminator.
WriteLineAsync​()
Inherited from TextWriter
Returns A task that represents the asynchronous write operation.
Asynchronously writes a line terminator to the text stream.
WriteLineAsync​(char[] buffer)
Inherited from TextWriter
buffer The character array to write to the text stream. If the character array is <see langword="null" /> , only the line terminator is written.
Returns A task that represents the asynchronous write operation.
Asynchronously writes an array of characters to the text stream, followed by a line terminator.
public object
GetLifetimeService​()
Inherited from MarshalByRefObject
Returns An object of type <see cref="T:System.Runtime.Remoting.Lifetime.ILease" /> used to control the lifetime policy for this instance.
Retrieves the current lifetime service object that controls the lifetime policy for this instance.
public object
InitializeLifetimeService​()
Inherited from MarshalByRefObject
Returns An object of type <see cref="T:System.Runtime.Remoting.Lifetime.ILease" /> used to control the lifetime policy for this instance. This is the current lifetime service object for this instance if one exists; otherwise, a new lifetime service object initialized to the value of the <see cref="P:System.Runtime.Remoting.Lifetime.LifetimeServices.LeaseManagerPollTime" /> property.
Obtains a lifetime service object to control the lifetime policy for this instance.
protected MarshalByRefObject
MemberwiseClone​(bool cloneIdentity)
Inherited from MarshalByRefObject
cloneIdentity <see langword="false" /> to delete the current <see cref="T:System.MarshalByRefObject" /> object's identity, which will cause the object to be assigned a new identity when it is marshaled across a remoting boundary. A value of <see langword="false" /> is usually appropriate. <see langword="true" /> to copy the current <see cref="T:System.MarshalByRefObject" /> object's identity to its clone, which will cause remoting client calls to be routed to the remote server object.
Returns A shallow copy of the current <see cref="T:System.MarshalByRefObject" /> object.
Creates a shallow copy of the current <see cref="T:System.MarshalByRefObject" /> object.
public bool
Equals​(object obj)
Inherited from object
obj The object to compare with the current object.
Returns <see langword="true" /> if the specified object is equal to the current object; otherwise, <see langword="false" /> .
Determines whether the specified object is equal to the current object.
protected void
Finalize​()
Inherited from object
Allows an object to try to free resources and perform other cleanup operations before it is reclaimed by garbage collection.
public int
GetHashCode​()
Inherited from object
Returns A hash code for the current object.
Serves as the default hash function.
public Type
GetType​()
Inherited from object
Returns The exact runtime type of the current instance.
Gets the <see cref="T:System.Type" /> of the current instance.
protected object
MemberwiseClone​()
Inherited from object
Returns A shallow copy of the current <see cref="T:System.Object" /> .
Creates a shallow copy of the current <see cref="T:System.Object" /> .