XmlSerializer Utf-8编码

时间:2009-11-20 10:09:40

标签: c# .net xml encoding

考虑以下代码

  XmlSerializer serializer = new XmlSerializer(typeof(Invoice));

  using (TextWriter writer = new StreamWriter(fileName))
  {
    // Serialize the object, and close the TextWriter.
    serializer.Serialize(writer, invoice);
    writer.Close();
  }

默认情况下,流编写器上没有设置编码。如果未在流编写器上设置编码,它是默认为UTF-8吗?

2 个答案:

答案 0 :(得分:20)

是,默认情况下创建StreamWriter是为了使用没有前导码的UTF-8。详情请见here

答案 1 :(得分:3)

是的,StreamWriter默认为UTF-8,如上所述here