StreamWriter.Encoding 属性

定义

获取在其中写入输出的 Encoding

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

属性值

Encoding

在当前实例的构造函数中指定的 Encoding;或者如果未指定编码,则为 UTF8Encoding

示例

以下示例检索指定 StreamWriter 实例的编码。

// 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())

注解

This property is necessary for some XML scenarios where a header must be written containing the encoding used by the StreamWriter. 这允许 XML 代码使用任意 StreamWriter XML 标头并生成正确的 XML 标头。

有关常见 I/O 任务的列表,请参阅 常见 I/O 任务

适用于

另请参阅