Looking on the web for how to do it.
Found several solutions: serialisation, XML etc.
Cannot decide which to use.
My List class contains a string, some booleans and two other Lists.
Awaiting some opinions that will be accepted with great gratitude. :)

Just storing and retrieving a list of Facts for a later session, so that things I added already won't be lost.

Perhaps it helps if I showed some code (under construction!)

class Fact
    {
        public string Name { get; set; }
        public string Question { get; set; }
        public bool MultiValued { get; set; }
        public bool Sought { get; set; }
        public List<string> legalist;
        public List<Value> valuelist;

        public Fact()
        {
            Name = string.Empty;
            Question = string.Empty;
            MultiValued = false;
            Sought = true;
            legalist = new List<string>();
            valuelist = new List<Value>();
        }

        public Fact(string item, string value) : this()
        {
            Name = item;
            Value V = new Value(value);           
            valuelist.Add(V);
        }

If you don't want to be able to "read" your serialised list, or to be able to import from a common format, don't use XML. It can be quite slow once you get into large amounts of objects.

Have you considered using SQL Express? That way you can have a "LocalDB" that is deployed with your application and can be used to store your data. It might also be worth looking at Document Databases for something like this. A local store is small, powerful and can be updated in real-time. Using file based storage, this would be tricky (but possible, leading to a lot of disk IO)

Comments
Good advise

Yes! Thank you! I just thought an SQL DB is used for something bigger. But indeed why not use a DB? Perhaps my list of Facts will become really big.
Any comments on my code btw?

Only two things strike me as a little off.

  1. You have no way of uniquely identifying a single "Fact". This could be important, might not be, up to you.
  2. Lists shouldn't be publically accessible. You should allow readonly access to your lists and manage them internally via class methods.

Uniqueness, I intend to test the list of Facts in my UI as I add a new Fact, or do you mean a singleton?
I'm aware that my value and legal lists can't stay public. Perhaps I turn them into properties, but thanks for reminding.

Like I said, uniqueness may not be relevant for your scenario, however, you should look at ways to stop things being duplicated (such as constraints against having the same Name for example)

Thanks again for the advice.
I'm attempting to translate the code in this book from 1986
Scan0002.jpg to C#.
As Modula-2 (I worked a lot with it in the previous century) is a totaly different programming paradigm, this looks fun to do. Certainly because there are no deadlines involved. Hope I can succeed.
I consider this thread solved. Will not hesitate to ask if more questions would pop up.

Edited 1 Year Ago by ddanbe: addition

This question has already been answered. Start a new discussion instead.