XML serialization serializes public fields & properties of object - Csharp.Net

Q.  Choose the correct one

1) XML serialization serializes the public fields and properties of an object.
2) XML serialization serializes the private fields and properties of an object.
3) XML serialization serializes only the public methods.

- Published on 31 Aug 15

a. Only 1
b. Only 2
c. Only 1 & 2
d. All of the above

ANSWER: Only 1
 
XML serialization can serialize only public data. You cannot serialize private data.

Example:
FileStreamfs = new FileStream(" MyFile.XML ", FileMode.Create);
XmlSerializerobj = new XmlSerializer(typeof(DateTime));
obj.Serialize(fs, System.DateTime.Now);
fs.Close();

Post your comment / Share knowledge


Enter the code shown above:

(Note: If you cannot read the numbers in the above image, reload the page to generate a new one.)