Table of Contents

Class TextWriter

Namespace
System.IO
Assembly
System.IO.Streams.dll

Represents a writer that can write a sequential series of characters. This class is abstract.

public abstract class TextWriter : MarshalByRefObject, IDisposable
Inheritance
TextWriter
Implements
Derived
Inherited Members
Extension Methods

Constructors

TextWriter()

protected TextWriter()

Fields

CoreNewLine

Stores the newline characters used for this TextWriter.

protected char[] CoreNewLine

Field Value

char[]

Properties

Encoding

When overridden in a derived class, returns the character encoding in which the output is written.

public abstract Encoding Encoding { get; }

Property Value

Encoding

NewLine

Gets or sets the line terminator string used by the current TextWriter.

public virtual string NewLine { get; set; }

Property Value

string

Methods

Close()

Closes the current writer and releases any system resources associated with the writer.

public virtual void Close()

Dispose()

Releases all resources used by the TextWriter object.

public void Dispose()

Dispose(bool)

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

protected virtual void Dispose(bool disposing)

Parameters

disposing bool

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

Flush()

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

public virtual void Flush()

Remarks

This default method does nothing, but derived classes can override the method to provide the appropriate functionality.

Flushing the stream will not flush its underlying encoder unless you explicitly call Flush() or Close(). Setting AutoFlush to true means that data will be flushed from the buffer to the stream, but the encoder state will not be flushed. This allows the encoder to keep its state (partial characters) so that it can encode the next block of characters correctly. This scenario affects UTF8 and UTF7 where certain characters can only be encoded after the encoder receives the adjacent character or characters.

Write(bool)

Writes the text representation of a bool value to the text stream.

public virtual void Write(bool value)

Parameters

value bool

The bool value to write.

Write(char)

Writes a character to the text stream.

public virtual void Write(char value)

Parameters

value char

The character to write to the text stream.

Write(char[])

Writes a character array to the text stream.

public virtual void Write(char[] buffer)

Parameters

buffer char[]

The character array to write to the text stream.

Write(char[], int, int)

Writes a subarray of characters to the text stream.

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

Parameters

buffer char[]

The character array to write data from.

index int

The character position in the buffer at which to start retrieving data.

count int

The number of characters to write.

Exceptions

ArgumentNullException

The buffer parameter is null.

ArgumentOutOfRangeException

index or count is negative.

ArgumentException

The buffer length minus index is less than count.

Write(double)

Writes the text representation of an 8-byte floating-point value to the text stream.

public virtual void Write(double value)

Parameters

value double

The 8-byte floating-point value to write.

Write(int)

Writes the text representation of a 4-byte signed integer to the text stream.

public virtual void Write(int value)

Parameters

value int

The 4-byte signed integer to write.

Write(long)

Writes the text representation of an 8-byte signed integer to the text stream.

public virtual void Write(long value)

Parameters

value long

The 8-byte signed integer to write.

Write(object)

Writes the text representation of an object to the text stream by calling the ToString() method on that object.

public virtual void Write(object value)

Parameters

value object

The object to write.

Write(float)

Writes the text representation of a 4-byte floating-point value to the text stream.

public virtual void Write(float value)

Parameters

value float

The 4-byte floating-point value to write.

Write(string)

Writes a string to the text stream.

public virtual void Write(string value)

Parameters

value string

The string to write.

Write(uint)

Writes the text representation of a 4-byte unsigned integer to the text stream.

[CLSCompliant(false)]
public virtual void Write(uint value)

Parameters

value uint

The 4-byte unsigned integer to write.

Write(ulong)

Writes the text representation of an 8-byte unsigned integer to the text stream.

[CLSCompliant(false)]
public virtual void Write(ulong value)

Parameters

value ulong

The 8-byte unsigned integer to write.

WriteLine()

Writes a line terminator to the text stream.

public virtual void WriteLine()

WriteLine(bool)

Writes the text representation of a bool value to the text stream, followed by a line terminator.

public virtual void WriteLine(bool value)

Parameters

value bool

The bool value to write.

WriteLine(char)

Writes a character to the text stream, followed by a line terminator.

public virtual void WriteLine(char value)

Parameters

value char

The character to write to the text stream.

WriteLine(char[])

Writes a character array to the text stream, followed by a line terminator.

public virtual void WriteLine(char[] buffer)

Parameters

buffer char[]

The character array to write to the text stream.

WriteLine(char[], int, int)

Writes a subarray of characters to the text stream, followed by a line terminator.

public virtual void WriteLine(char[] buffer, int index, int count)

Parameters

buffer char[]

The character array to write data from.

index int

The character position in the buffer at which to start retrieving data.

count int

The number of characters to write.

Exceptions

ArgumentNullException

The buffer parameter is null.

ArgumentOutOfRangeException

index or count is negative.

ArgumentException

The buffer length minus index is less than count.

WriteLine(double)

Writes the text representation of an 8-byte floating-point value to the text stream, followed by a line terminator.

public virtual void WriteLine(double value)

Parameters

value double

The 8-byte floating-point value to write.

WriteLine(int)

Writes the text representation of a 4-byte signed integer to the text stream, followed by a line terminator.

public virtual void WriteLine(int value)

Parameters

value int

The 4-byte signed integer to write.

WriteLine(long)

Writes the text representation of an 8-byte signed integer to the text stream, followed by a line terminator.

public virtual void WriteLine(long value)

Parameters

value long

The 8-byte signed integer to write.

WriteLine(object)

Writes the text representation of an object to the text stream by calling the ToString() method on that object, followed by a line terminator.

public virtual void WriteLine(object value)

Parameters

value object

The object to write.

WriteLine(float)

Writes the text representation of a 4-byte floating-point value to the text stream, followed by a line terminator.

public virtual void WriteLine(float value)

Parameters

value float

The 4-byte floating-point value to write.

WriteLine(string)

Writes a string to the text stream, followed by a line terminator.

public virtual void WriteLine(string value)

Parameters

value string

The string to write.

WriteLine(uint)

Writes the text representation of a 4-byte unsigned integer to the text stream, followed by a line terminator.

[CLSCompliant(false)]
public virtual void WriteLine(uint value)

Parameters

value uint

The 4-byte unsigned integer to write.

WriteLine(ulong)

Writes the text representation of an 8-byte unsigned integer to the text stream, followed by a line terminator.

[CLSCompliant(false)]
public virtual void WriteLine(ulong value)

Parameters

value ulong

The 8-byte unsigned integer to write.