What is the best way to save a list of objects to an XML file and load that list back using C#?

Posted by Siracuse on Stack Overflow See other posts from Stack Overflow or by Siracuse
Published on 2010-04-23T02:43:16Z Indexed on 2010/04/23 2:53 UTC
Read the original article Hit count: 387

Filed under:
|

I have a list of "Gesture" classes in my application:

List<Gesture> gestures = new List<Gesture>();

These gesture classes are pretty simple:

public class Gesture
{
    public String Name { get; set; }
    public List<Point> Points { get; set; }
    public List<Point> TransformedPoints { get; set; }    

    public Gesture(List<Point> Points, String Name)
    {
        this.Points = new List<Point>(Points);
        this.Name = Name;
    }
}

I would like to allow the user to both save the current state of "gestures" to a file and also be able to load a file that contains the data of the gestures.

What is the standard way to do this in C#?

Should I use Serialization? Should I write a class to handle writing/reading this XML file by hand myself? Are there any other ways?

© Stack Overflow or respective owner

Related posts about c#

Related posts about .NET