public class StringWriter : TextWriter
Object
MarshalByRefObject
TextWriter
StringWriterThis type implements IDisposable.
mscorlib
BCL
Implements a TextWriter that writes information to a string.
System.IO Namespace
StringWriter Constructors
StringWriter() Constructor
StringWriter(System.IFormatProvider) Constructor
StringWriter(System.Text.StringBuilder) Constructor
StringWriter(System.Text.StringBuilder, System.IFormatProvider) Constructor
StringWriter Methods
StringWriter.Close Method
StringWriter.Dispose Method
StringWriter.GetStringBuilder Method
StringWriter.ToString Method
StringWriter.Write(System.String) Method
StringWriter.Write(char[], int, int) Method
StringWriter.Write(char) Method
StringWriter Properties
public StringWriter();
Constructs and initializes a new instance of the StringWriter class.
A new StringBuilder is automatically created and associated with the new StringWriter instance.
System.IO.StringWriter Class, System.IO Namespace
public StringWriter(IFormatProvider formatProvider);
Constructs and initializes a new instance of the StringWriter class with the specified format provider.
- formatProvider
- A IFormatProvider object that defines formatting.
System.IO.StringWriter Class, System.IO Namespace
public StringWriter(StringBuilder sb);
Constructs and initializes a new instance of the StringWriter class that writes to the specified StringBuilder.
- sb
- The StringBuilder to write to.
Exception Type Condition ArgumentNullException sb is null
.
System.IO.StringWriter Class, System.IO Namespace
public StringWriter(StringBuilder sb, IFormatProvider formatProvider);
Constructs and initializes a new instance of the StringWriter class that writes to the specified StringBuilder and has the specified format provider.
- sb
- The StringBuilder to write to.
- formatProvider
- A IFormatProvider object that defines formatting.
Exception Type Condition ArgumentNullException sb is null
.
System.IO.StringWriter Class, System.IO Namespace
public override void Close();
Closes the current StringWriter instance.
[Note: This version of System.IO.StringWriter.Close is equivalent to System.IO.StringWriter.Dispose(System.Boolean)(true
).This method overrides System.IO.Stream.Close.
]
System.IO.StringWriter Class, System.IO Namespace
protected override void Dispose(bool disposing);
Releases the unmanaged resources used by the StringWriter and optionally releases the managed resources.
- disposing
true
to release both managed and unmanaged resources;false
to release only unmanaged resources.
When the disposing parameter istrue
, this method releases all resources held by any managed objects that this StringWriter references. This method invokes theDispose()
method of each referenced object.[Note: System.IO.StringWriter.Dispose(System.Boolean) can be called multiple times by other objects. When overriding System.IO.StringWriter.Dispose(System.Boolean)(Boolean), be careful not to reference objects that have been previously disposed in an earlier call to System.IO.StringWriter.Dispose(System.Boolean) .]
System.IO.StringWriter Class, System.IO Namespace
public virtual StringBuilder GetStringBuilder();
Returns the underlying StringBuilder .
The underlying StringBuilder .
This method returns either the StringBuilder that was passed to the constructor, or the StringBuilder that was automatically created.[Behaviors: As described above.]
System.IO.StringWriter Class, System.IO Namespace
public override string ToString();
Returns a string containing the characters written to the current StringWriter instance so far.
The String containing the characters written to the current StringWriter instance.
[Note: This method overrides System.Object.ToString.]
System.IO.StringWriter Class, System.IO Namespace
public override void Write(string value);
Writes a string to the current instance of the StringWriter.
- value
- The String to write. If value is
null
, nothing is written.
Exception Type Condition ObjectDisposedException The writer is closed.
[Note: This method overrides System.IO.TextWriter.Write(System.Char) .]
System.IO.StringWriter Class, System.IO Namespace
public override void Write(char[] buffer, int index, int count);
Writes the specified region of a character array to this instance of the StringWriter.
- buffer
- The Char array to read data from.
- index
- A Int32 that specifies the index at which to begin reading from buffer .
- count
- A Int32 that specifies the maximum number of characters to write.
Exception Type Condition ArgumentNullException buffer is null
.ArgumentOutOfRangeException index < 0 -or-
count < zero.
ArgumentException (index + count ) > buffer .
Length.ObjectDisposedException The writer is closed.
[Note: This method overrides System.IO.TextWriter.Write(System.Char).]
System.IO.StringWriter Class, System.IO Namespace
public override void Write(char value);
Writes a character to the current instance of the StringWriter .
- value
- The Char to write.
Exception Type Condition ObjectDisposedException The writer is closed.
[Note: This method overrides System.IO.TextWriter.Write(System.Char).]
System.IO.StringWriter Class, System.IO Namespace
public override Encoding Encoding { get; }
Gets the Encoding in which the output is written.
The Encoding in which the output is written.
[Behaviors: As described above.]
[Usage: This property is required in some XML scenarios where a header must be written containing the encoding used by the StringWriter. This allows XML code to consume an arbitrary StringWriter and generate a correct XML header.]
System.IO.StringWriter Class, System.IO Namespace