开发者

XmlSerializer Utf-8 encoding

开发者 https://www.devze.com 2022-12-11 20:05 出处:网络
Consider the code below XmlSerializer serializer = new XmlSerializer(typeof(Invoice)); using (TextWriter writer = new StreamWriter(fileName))

Consider the code below

  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();
  }

No encoding is set on the stream writer by default. Does it default to UTF-8 if you don't set an开发者_Go百科 encoding on the stream writer?


Yes, by default StreamWriter is created for using UTF-8 without preamble. See details here


Yes, the StreamWriter does default to UTF-8 as mentioned here

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号