0

I am working with c# and I have a list of type list where Family is a class with this structure:

public class Family
    {
        public Father father;
        public Mother mother;
        public int IdFamily { get; set; }
    }

Father and Mother are also classes with their own attributes.

My list has got data about the families. I want to store all that data from the list into a txt files.

How I can do this using System.IO and StreamWriter?

Ignacio Alorre
  • 7,307
  • 8
  • 57
  • 94

1 Answers1

1

If you go for Json then it's quite straight forward with Newtonsoft

string json = JsonConvert.SerializeObject(family, Formatting.Indented);
File.WriteAllText(path, json);
Ofir Winegarten
  • 9,215
  • 2
  • 21
  • 27