Редагувати

Поділитися через


StreamWriter.Encoding Property

Definition

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.

Applies to

See also