StreamWriter.Encoding Property
Definition
Important
Some information relates to prerelease product that may be substantially modified before it’s released. Microsoft makes no warranties, express or implied, with respect to the information provided here.
Gets the Encoding in which the output is written.
public:
virtual property System::Text::Encoding ^ Encoding { System::Text::Encoding ^ get(); };
public override System.Text.Encoding Encoding { get; }
member this.Encoding : System.Text.Encoding
Public Overrides ReadOnly Property Encoding As Encoding
Property Value
The Encoding specified in the constructor for the current instance, or UTF8Encoding if an encoding was not specified.
Examples
The following example retrieves the encoding of the specified StreamWriter instance.
// Write out the current text encoding
sw->WriteLine( "Encoding: {0}",
sw->Encoding->ToString() );
// Write out the current text encoding
sw.WriteLine("Encoding: {0}",
sw.Encoding.ToString());
' Write out the current text encoding.
Sw.WriteLine("Encoding: {0}", _
Sw.Encoding.ToString())
Remarks
This property is necessary for some XML scenarios where a header must be written containing the encoding used by the StreamWriter. This allows the XML code to consume an arbitrary StreamWriter and generate the correct XML header.
For a list of common I/O tasks, see Common I/O Tasks.