Created
December 18, 2017 19:10
-
-
Save gustavodaquino/bde9faeae90085d6d39f3eb5fb8c7bff to your computer and use it in GitHub Desktop.
Serializing a C# class to XML
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
[Serializable] | |
public class Person | |
{ | |
public string FirstName { get; set; } | |
public string LastName { get; set; } | |
public int Age { get; set; } | |
} | |
var serializer = new XmlSerializer(typeof(Person)); | |
string xml; | |
using (var stringWriter = new StringWriter()) | |
{ | |
serializer.Serialize(stringWriter, new Person { FirstName = "John", LastName = "Doe", Age = 42 }); | |
xml = stringWriter.ToString(); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment