It would probably be easier to use a
BindingList
and serialize to XML.
Here is an excellent example:
A Detailed Data Binding Tutorial[
^]
If you want information about serializing to XML, see:
[
^]
Example:
using System.Xml.Serialization;
public static void TestSerialization()
{
myClass person = new myClass();
List<myClass> listStr = new List<myClass>();
listStr.Add(person);
var x = new XmlSerializer(listStr.GetType());
using (var strWriter = new StringWriter())
{
x.Serialize(strWriter, listStr);
File.WriteAllText("test.xml", strWriter.ToString());
}
}