views:

849

answers:

2

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 encoding on the stream writer?

A: 

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

AdaTheDev
+4  A: 

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

elder_george