Class TextWriter
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
NewLine
Gets or sets the line terminator string used by the current TextWriter.
public virtual string NewLine { get; set; }
Property Value
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
booltrue 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
Write(char)
Writes a character to the text stream.
public virtual void Write(char value)
Parameters
value
charThe 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
intThe character position in the buffer at which to start retrieving data.
count
intThe number of characters to write.
Exceptions
- ArgumentNullException
The
buffer
parameter is null.- ArgumentOutOfRangeException
index
orcount
is negative.- ArgumentException
The
buffer
length minusindex
is less thancount
.
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
doubleThe 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
intThe 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
longThe 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
objectThe 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
floatThe 4-byte floating-point value to write.
Write(string)
Writes a string to the text stream.
public virtual void Write(string value)
Parameters
value
stringThe 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
uintThe 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
ulongThe 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
WriteLine(char)
Writes a character to the text stream, followed by a line terminator.
public virtual void WriteLine(char value)
Parameters
value
charThe 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
intThe character position in the buffer at which to start retrieving data.
count
intThe number of characters to write.
Exceptions
- ArgumentNullException
The
buffer
parameter is null.- ArgumentOutOfRangeException
index
orcount
is negative.- ArgumentException
The
buffer
length minusindex
is less thancount
.
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
doubleThe 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
intThe 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
longThe 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
objectThe 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
floatThe 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
stringThe 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
uintThe 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
ulongThe 8-byte unsigned integer to write.