Click here to Skip to main content
15,891,657 members
Please Sign up or sign in to vote.
5.00/5 (1 vote)
See more:
What is the best method of saving and loading data structure in c#?

I want save this data structure and load in other time.
List<List<Array>> Mainsetlistbox090 = new List<List<Array>>();


thanks
Posted

The declaration in Question has little sense: what you want use a list of lists of untyped arrays?!

OK, in general, most simple and effective: put it in the class and serialize/deserialize its instance using DataContract and DataContractSerializer:
http://msdn.microsoft.com/en-us/library/system.runtime.serialization.datacontractserializer.aspx[^].

All you need is the attribute [DataContract] for the class and [DataMember] for the member you need to store/load. There are many other ways, read on serialization in general Microsoft documentation and elsewhere.
 
Share this answer
 
Comments
Espen Harlinn 6-Feb-11 14:58pm    
Makes sence, and a 5 :)
If you're going to use xml, you might want to have a look at linq.

Below is an example for object serialization taken from msdn.
Of course you'd have to research and do some work to serialize lists and arrays...

using System;
using System.IO;
using System.Linq;
using System.Xml;
using System.Xml.Serialization;
using System.Xml.Linq;
public class XElementContainer
{
    public XElement member;
    public XElementContainer()
    {
        member = XLinqTest.CreateXElement();
    }
    public override string ToString()
    {
        return member.ToString();
    }
}
public class XElementNullContainer
{
    public XElement member;
    public XElementNullContainer()
    {
    }
}
class XLinqTest
{
    static void Main(string[] args)
    {
        Test<XElementNullContainer>(new XElementNullContainer());
        Test<XElement>(CreateXElement());
        Test<XElementContainer>(new XElementContainer());
    }
    public static XElement CreateXElement()
    {
        XNamespace ns = "http://www.adventure-works.com";
        return new XElement(ns + "aw");
    }
    static void Test<T>(T obj)
    {
        using (MemoryStream stream = new MemoryStream())
        {
            XmlSerializer s = new XmlSerializer(typeof(T));
            Console.WriteLine("Testing for type: {0}", typeof(T));
            s.Serialize(XmlWriter.Create(stream), obj);
            stream.Flush();
            stream.Seek(0, SeekOrigin.Begin);
            object o = s.Deserialize(XmlReader.Create(stream));
            Console.WriteLine("  Deserialized type: {0}", o.GetType());
        }
    }
}
 
Share this answer
 
v3

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900