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.​StreamWriter
Assembly: System.Runtime
Inheritance: object → MarshalByRefObject → TextWriter → StreamWriter
Implemented Interfaces
- IAsyncDisposable Implemented by: TextWriter
- IDisposable Implemented by: TextWriter
Implements a <see cref="T:System.IO.TextWriter" /> for writing characters to a stream in a particular encoding.
Fields and Constants
public static readonly
StreamWriter
Null
Provides a <see langword="StreamWriter" /> with no backing store that can be written to, but not read from.
protected
char[]
CoreNewLine
Stores the newline characters used for this <see langword="TextWriter" /> .
Properties
public
bool
AutoFlush
Gets or sets a value indicating whether the <see cref="T:System.IO.StreamWriter" /> will flush its buffer to the underlying stream after every call to <see cref="M:System.IO.StreamWriter.Write(System.Char)" /> .
public
Stream
BaseStream
Gets the underlying stream that interfaces with a backing store.
Encoding
Gets the <see cref="T:System.Text.Encoding" /> in which the output is written.
public
IFormatProvider
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 langword="StreamWriter" /> object and the underlying stream.
protected
void
Dispose​(bool disposing)
Causes any buffered data to be written to the underlying stream, releases the unmanaged resources used by the <see cref="T:System.IO.StreamWriter" /> , and optionally the managed resources.
disposing
<see langword="true" /> to release both managed and unmanaged resources; <see langword="false" /> to release only unmanaged resources.
DisposeAsync​()
Asynchronously writes any buffered data to the underlying stream and releases the unmanaged resources used by the <see cref="T:System.IO.StreamWriter" /> .
Returns A task that represents the asynchronous dispose operation.
public
void
Flush​()
Clears all buffers for the current writer and causes any buffered data to be written to the underlying stream.
FlushAsync​()
Clears all buffers for this stream asynchronously and causes any buffered data to be written to the underlying device.
Returns A task that represents the asynchronous flush operation.
FlushAsync​(Threading.​CancellationToken cancellationToken)
Clears all buffers for this stream asynchronously and causes any buffered data to be written to the underlying device.
Returns A <see cref="T:System.Threading.Tasks.Task" /> that represents the asynchronous flush operation.
cancellationToken
The <see cref="T:System.Threading.CancellationToken" /> to monitor for cancellation requests.
public
void
Write​(char value)
Writes a character to the stream.
value
The character to write to the stream.
public
void
Write​(char[] buffer)
Writes a character array to the stream.
buffer
A character array containing the data to write. If <paramref name="buffer" /> is <see langword="null" /> , nothing is written.
public
void
Write​(char[] buffer,
int index,
int count)
Writes a subarray of characters to the stream.
buffer
A character array that contains the data to write.
index
The character position in the buffer at which to start reading data.
count
The maximum number of characters to write.
public
void
Write​(ReadOnlySpan<​char> buffer)
Writes a character span to the stream.
buffer
The character span to write.
public
void
Write​(string value)
Writes a string to the stream.
value
The string to write to the stream. If <paramref name="value" /> is null, nothing is written.
public
void
Write​(string format,
object arg0)
Writes a formatted string to the stream, using the same semantics as the <see cref="M:System.String.Format(System.String,System.Object)" /> method.
format
A composite format string.
arg0
The object to format and write.
public
void
Write​(string format,
object arg0,
object arg1)
Writes a formatted string to the stream using the same semantics as the <see cref="M:System.String.Format(System.String,System.Object,System.Object)" /> method.
format
A composite format string.
arg0
The first object to format and write.
arg1
The second object to format and write.
public
void
Write​(string format,
object arg0,
object arg1,
object arg2)
Writes a formatted string to the stream, using the same semantics as the <see cref="M:System.String.Format(System.String,System.Object,System.Object,System.Object)" /> method.
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.
public
void
Write​(string format,
object[] arg)
Writes a formatted string to the stream, using the same semantics as the <see cref="M:System.String.Format(System.String,System.Object[])" /> method.
format
A composite format string.
arg
An object array that contains zero or more objects to format and write.
public
void
Write​(string format,
ReadOnlySpan<​object> arg)
Writes a formatted string to the stream, using the same semantics as <see cref="M:System.String.Format(System.String,System.ReadOnlySpan{System.Object})" /> .
format
A composite format string.
arg
An object span that contains zero or more objects to format and write.
WriteAsync​(char value)
Asynchronously writes a character to the stream.
Returns A task that represents the asynchronous write operation.
value
The character to write to the stream.
WriteAsync​(char[] buffer,
int index,
int count)
Asynchronously writes a subarray of characters to the stream.
Returns A task that represents the asynchronous write operation.
buffer
A character array that contains the data to write.
index
The character position in the buffer at which to begin reading data.
count
The maximum number of characters to write.
WriteAsync​(ReadOnlyMemory<​char> buffer,
Threading.​CancellationToken cancellationToken = null)
Asynchronously writes a character memory region to the stream.
Returns A task that represents the asynchronous write operation.
buffer
The character memory region to write to the stream.
cancellationToken
The token to monitor for cancellation requests. The default value is <see cref="P:System.Threading.CancellationToken.None" /> .
WriteAsync​(string value)
Asynchronously writes a string to the stream.
Returns A task that represents the asynchronous write operation.
value
The string to write to the stream. If <paramref name="value" /> is <see langword="null" /> , nothing is written.
public
void
WriteLine​(ReadOnlySpan<​char> buffer)
Writes the text representation of a character span to the stream, followed by a line terminator.
buffer
The character span to write to the stream.
public
void
WriteLine​(string value)
Writes a string to the stream, followed by a line terminator.
value
The string to write. If <paramref name="value" /> is <see langword="null" /> , only the line terminator is written.
public
void
WriteLine​(string format,
object arg0)
Writes a formatted string and a new line to the stream, using the same semantics as the <see cref="M:System.String.Format(System.String,System.Object)" /> method.
format
A composite format string.
arg0
The object to format and write.
public
void
WriteLine​(string format,
object arg0,
object arg1)
Writes a formatted string and a new line to the stream, using the same semantics as the <see cref="M:System.String.Format(System.String,System.Object,System.Object)" /> method.
format
A composite format string.
arg0
The first object to format and write.
arg1
The second object to format and write.
public
void
WriteLine​(string format,
object arg0,
object arg1,
object arg2)
Writes out a formatted string and a new line to the stream, using the same semantics as <see cref="M:System.String.Format(System.String,System.Object)" /> .
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.
public
void
WriteLine​(string format,
object[] arg)
Writes out a formatted string and a new line to the stream, using the same semantics as <see cref="M:System.String.Format(System.String,System.Object)" /> .
format
A composite format string.
arg
An object array that contains zero or more objects to format and write.
public
void
WriteLine​(string format,
ReadOnlySpan<​object> arg)
Writes out a formatted string and a new line to the stream, using the same semantics as <see cref="M:System.String.Format(System.String,System.ReadOnlySpan{System.Object})" /> .
format
A composite format string.
arg
An object span that contains zero or more objects to format and write.
WriteLineAsync​()
Asynchronously writes a line terminator to the stream.
Returns A task that represents the asynchronous write operation.
WriteLineAsync​(char value)
Asynchronously writes a character to the stream, followed by a line terminator.
Returns A task that represents the asynchronous write operation.
value
The character to write to the stream.
WriteLineAsync​(char[] buffer,
int index,
int count)
Asynchronously writes a subarray of characters to the stream, followed by a line terminator.
Returns A task that represents the asynchronous write operation.
buffer
The character array to write data from.
index
The character position in the buffer at which to start reading data.
count
The maximum number of characters to write.
WriteLineAsync​(ReadOnlyMemory<​char> buffer,
Threading.​CancellationToken cancellationToken = null)
Asynchronously writes the text representation of a character memory region to the stream, followed by a line terminator.
Returns A task that represents the asynchronous write operation.
buffer
The character memory region to write to the stream.
cancellationToken
The token to monitor for cancellation requests. The default value is <see cref="P:System.Threading.CancellationToken.None" /> .
WriteLineAsync​(string value)
Asynchronously writes a string to the stream, followed by a line terminator.
Returns A task that represents the asynchronous write operation.
value
The string to write. If the value is <see langword="null" /> , only a line terminator is written.
public
void
Dispose​()
Inherited from TextWriter
Releases all resources used by the <see cref="T:System.IO.TextWriter" /> object.
public
void
Write​(bool value)
Inherited from TextWriter
Writes the text representation of a <see langword="Boolean" /> value to the text stream.
value
The <see langword="Boolean" /> value to write.
public
void
Write​(decimal value)
Inherited from TextWriter
Writes the text representation of a decimal value to the text stream.
value
The decimal value to write.
public
void
Write​(double value)
Inherited from TextWriter
Writes the text representation of an 8-byte floating-point value to the text stream.
value
The 8-byte floating-point value to write.
public
void
Write​(int value)
Inherited from TextWriter
Writes the text representation of a 4-byte signed integer to the text stream.
value
The 4-byte signed integer to write.
public
void
Write​(long value)
Inherited from TextWriter
Writes the text representation of an 8-byte signed integer to the text stream.
value
The 8-byte signed integer to write.
public
void
Write​(object value)
Inherited from TextWriter
Writes the text representation of an object to the text stream by calling the <see langword="ToString" /> method on that object.
value
The object to write.
public
void
Write​(Single value)
Inherited from TextWriter
Writes the text representation of a 4-byte floating-point value to the text stream.
value
The 4-byte floating-point value to write.
public
void
Write​(Text.​StringBuilder value)
Inherited from TextWriter
Writes a string builder to the text stream.
value
The string, as a string builder, to write to the text stream.
public
void
Write​(uint value)
Inherited from TextWriter
Writes the text representation of a 4-byte unsigned integer to the text stream.
value
The 4-byte unsigned integer to write.
public
void
Write​(ulong value)
Inherited from TextWriter
Writes the text representation of an 8-byte unsigned integer to the text stream.
value
The 8-byte unsigned integer to write.
WriteAsync​(char[] buffer)
Inherited from TextWriter
Writes a character array to the text stream asynchronously.
Returns A task that represents the asynchronous write operation.
buffer
The character array to write to the text stream. If <paramref name="buffer" /> is <see langword="null" /> , nothing is written.
WriteAsync​(Text.​StringBuilder? value,
Threading.​CancellationToken cancellationToken = null)
Inherited from TextWriter
Asynchronously writes a string builder to the text stream.
Returns A task that represents the asynchronous write operation.
value
The string, as a string builder, to write to the text stream.
cancellationToken
The token to monitor for cancellation requests. The default value is <see cref="P:System.Threading.CancellationToken.None" /> .
public
void
WriteLine​()
Inherited from TextWriter
Writes a line terminator to the text stream.
public
void
WriteLine​(bool value)
Inherited from TextWriter
Writes the text representation of a <see langword="Boolean" /> value to the text stream, followed by a line terminator.
value
The <see langword="Boolean" /> value to write.
public
void
WriteLine​(char value)
Inherited from TextWriter
Writes a character to the text stream, followed by a line terminator.
value
The character to write to the text stream.
public
void
WriteLine​(char[] buffer)
Inherited from TextWriter
Writes an array of characters to the text stream, followed by a line terminator.
buffer
The character array from which data is read.
public
void
WriteLine​(char[] buffer,
int index,
int count)
Inherited from TextWriter
Writes a subarray of characters to the text stream, followed by a line terminator.
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.
public
void
WriteLine​(decimal value)
Inherited from TextWriter
Writes the text representation of a decimal value to the text stream, followed by a line terminator.
value
The decimal value to write.
public
void
WriteLine​(double value)
Inherited from TextWriter
Writes the text representation of a 8-byte floating-point value to the text stream, followed by a line terminator.
value
The 8-byte floating-point value to write.
public
void
WriteLine​(int value)
Inherited from TextWriter
Writes the text representation of a 4-byte signed integer to the text stream, followed by a line terminator.
value
The 4-byte signed integer to write.
public
void
WriteLine​(long value)
Inherited from TextWriter
Writes the text representation of an 8-byte signed integer to the text stream, followed by a line terminator.
value
The 8-byte signed integer to write.
public
void
WriteLine​(object value)
Inherited from TextWriter
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.
value
The object to write. If <paramref name="value" /> is <see langword="null" /> , only the line terminator is written.
public
void
WriteLine​(Single value)
Inherited from TextWriter
Writes the text representation of a 4-byte floating-point value to the text stream, followed by a line terminator.
value
The 4-byte floating-point value to write.
public
void
WriteLine​(Text.​StringBuilder value)
Inherited from TextWriter
Writes the text representation of a string builder to the text stream, followed by a line terminator.
value
The string, as a string builder, to write to the text stream.
public
void
WriteLine​(uint value)
Inherited from TextWriter
Writes the text representation of a 4-byte unsigned integer to the text stream, followed by a line terminator.
value
The 4-byte unsigned integer to write.
public
void
WriteLine​(ulong value)
Inherited from TextWriter
Writes the text representation of an 8-byte unsigned integer to the text stream, followed by a line terminator.
value
The 8-byte unsigned integer to write.
WriteLineAsync​(char[] buffer)
Inherited from TextWriter
Asynchronously writes an array of characters to the text stream, followed by a line terminator.
Returns A task that represents the asynchronous write operation.
buffer
The character array to write to the text stream. If the character array is <see langword="null" /> , only the line terminator is written.
WriteLineAsync​(Text.​StringBuilder? value,
Threading.​CancellationToken cancellationToken = null)
Inherited from TextWriter
Asynchronously writes the text representation of a string builder to the text stream, followed by a line terminator.
Returns A task that represents the asynchronous write operation.
value
The string, as a string builder, to write to the text stream.
cancellationToken
The token to monitor for cancellation requests. The default value is <see cref="P:System.Threading.CancellationToken.None" /> .
public
object
GetLifetimeService​()
Inherited from MarshalByRefObject
Retrieves the current lifetime service object that controls the lifetime policy for this instance.
Returns An object of type <see cref="T:System.Runtime.Remoting.Lifetime.ILease" /> used to control the lifetime policy for this instance.
public
object
InitializeLifetimeService​()
Inherited from MarshalByRefObject
Obtains a lifetime service object to control the lifetime policy for this instance.
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.
protected
MarshalByRefObject
MemberwiseClone​(bool cloneIdentity)
Inherited from MarshalByRefObject
Creates a shallow copy of the current <see cref="T:System.MarshalByRefObject" /> object.
Returns A shallow copy of the current <see cref="T:System.MarshalByRefObject" /> object.
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.
public
bool
Equals​(object obj)
Inherited from object
Determines whether the specified object is equal to the current object.
Returns <see langword="true" /> if the specified object is equal to the current object; otherwise, <see langword="false" /> .
obj
The object to compare with 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
Serves as the default hash function.
Returns A hash code for the current object.
public
Type
GetType​()
Inherited from object
Gets the <see cref="T:System.Type" /> of the current instance.
Returns The exact runtime type of the current instance.
protected
object
MemberwiseClone​()
Inherited from object
Creates a shallow copy of the current <see cref="T:System.Object" /> .
Returns A shallow copy of the current <see cref="T:System.Object" /> .
public
string
ToString​()
Inherited from object
Returns a string that represents the current object.
Returns A string that represents the current object.